Re: Class code refuses to run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 10/08/2021 19:12, JEFFRY KILLEN wrote:

On Aug 10, 2021, at 10:19 AM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx> wrote:


On 10/08/2021 17:43, JEFFRY KILLEN wrote:
On Aug 10, 2021, at 12:12 AM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx> wrote:



On 10 August 2021 01:36:01 BST, JEFFRY KILLEN <jekillen@xxxxxxxxxxx> wrote:
Hello;

I have a web page I am developing.

It has images embedded in it.

The src attribute is ./?tag=guitar&amp;type=img

The php code from the html file is:
</php
// preliminary irrelevant code
require_once('php/imageServer.php');

if($_GET['tag'])
{
  //// file_put_contents('test.txt', "Hello?...img...");
/*
the following was working before I expanded it out to running code as written.
it still should work.
(new _IMG_SERV())->serv($_GET);
*/
   $_x = new _IMG_SERV();
   $_x->serv($_GET);
}
?>

the serv method in the class is

public function serv($_a)
             {
              file_put_contents('test.txt', "Hello?...img...");
              switch($_a['type'])
                {
                 case 'img':
                 header('Content-Type: image/jpeg');
                 imagedestroy(imagejpeg(imagecreatefromjpeg(self::$_imgDir.self::$_imgIndex[$_a['tag']])));
                 break;
                 case 'txt':
                 if(file_exists(self::$_imgDir.self::$_txtIndex[$_a['tag']]['img']))
                   {
                    header('Content-Type: image/jpeg');
                    imagedestroy(imagejpeg(imagecreatefromjpeg(self::$_txtIndex[$_a['tag']]['img'])));
                   }
                 else
                   {
                    /*
                     create text image, save for future ref and serve
                    */
                   }
                 break;
                }
             }

This HAS all been working up to a point. BUT the serv function is now refusing to run.
There are no php, javascript or html related errors.

You will see 'file_put_contents('test.txt', "Hello?...img...");'
Because this is an async request for a resource I cannot use print or echo to sample
code progress. So I have strings written to a text file. The call to file_put_contents('test.txt', "Hello?...img...");
in the top of the serv method is not running. It IS running in the top of the get conditional in the index page
if I uncomment it.

Does anyone know why apache and/or php, and/or possibly the browser would fail to serve a resource
like this when it so far has been working most of the day today? I cannot see anything I have done wrong.
data:
MacOS High Sierra, apache on localhost
Thank you for time and attention;
JK
You say there are no errors, but presumably that just means none being displayed? Have you looked at the error logs?

Also, the imagedestroy calls here aren't really necessary, as you should be exiting immediately after outputting the image data.
I don't have my server set up to log errors. It is a dev server on local host.
I use Firefox as dev/test browser. It has dev tools, one of which is network.
The requests for image resources represented by the get queries are returning
200, ok. and the image is not displayed. Only the alt string is displayed.

However I did make some subtile changes just before the problem appeared. I am going to roll back those
changes and see what happens. The changes should not be invalid. It just amounts to when the php script
has a full version of resource path.
self::$_imgDir.self::$_imgIndex[$_a['tag']]
Where self::@_imgDir is a string representing the directory location
and self::$_imgIndex[$_a['tag']] is the file name.
I used to have the complete path/file name in self::$_imgIndex.
self::$_imgIndex is set with the contents of an external php script that is required by the class __construct method.

Thank you for time and attention
JK
Turn on error logs locally, they're absolutely essential for local development. There's also a pretty good case to turn on the display of errors locally too (which is different from error logging to a log file).

As for the image, you say you see the alt text, but you shouldn't see that if you're requesting only the image, as the alt attribute it part of the HTML, and you can't send mixed content via the same request with PHP that I'm aware of.

--
Ashley Sheridan
https://www.ashleysheridan.co.uk
I do get php error displayed locally. But not for async requests in the usual manner.

The alt attribute of the img tag is html. It is what is displayed if the image does
not arrive at the browser, as in case the server cannot find the file. Or in this
case the image is not being sent. The image is not being sent because the
serv method is being blocked from executing.

if the php interpreter is doing background security audits why did it take so
many test runs for it to decide the code was insecure or otherwise objectionable?

I did roll back the subtile changes mentioned in my earlier response with no improvement.

When I work with 'ajax' async requests often errors generated by php are included
in the response and are not displayed in lew of the html. So logging would
capture these errors?

Thank you for your responses;
JK

I don't really understand what you mean by async requests. You're displaying an image with an `<img>` tag. Copy that URL into your browser to request _only_ the image. What does that show you?

I did mention that error logging and error display are two different things. One outputs to the browser, the other to a log file within the standard Apache/Nginx/IIS log area (or a specific directory if you've set up the site to do that). If you're outputting an image, and the error occurs _after_ you've sent the image content headers, the result will be garbage that your browser won't know how to display, so it will likely show nothing, which is why the log _file_ is most important here. I suspect that logging is still happening, as it's highly unusual for it to ever be disabled, and I don't know why anyone would ever want to.

The PHP interpreter is not doing security checks on your code. I believe that the point you've rolled back to is in-fact not the last place it ran successfully. If in doubt, a versioning tool like Git is invaluable, as you can create branches and roll back to any arbitrary point you made a commit if you wish.

--
Ashley Sheridan
https://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux