Re: Class code refuses to run

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

 




> 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



[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