Re: Class code refuses to run
[email protected] (Pascal Schorde)
| Newsgroups | php.general |
|---|---|
| Message-ID | <CA+6OSs6BMRkmWFPTu5OC9Qhag7cbieNNyUiktO24Vm_RcOd7HQ@mail.gmail.com> |
You can inspect the maybe faulty response coming from php by using the web dev console (Ctrl + i). In the network tab is the async call from ajax with its response. Or did you do this already? Additionally xdebug dumps php errors in a little nicer format. JEFFRY KILLEN <[email protected]> schrieb am Di., 10. Aug. 2021, 20:13: > > > > On Aug 10, 2021, at 10:19 AM, Ashley Sheridan <[email protected]> > wrote: > > > > > > On 10/08/2021 17:43, JEFFRY KILLEN wrote: > >> > >>> On Aug 10, 2021, at 12:12 AM, Ashley Sheridan < > [email protected]> wrote: > >>> > >>> > >>> > >>> On 10 August 2021 01:36:01 BST, JEFFRY KILLEN <[email protected]> > wrote: > >>>> Hello; > >>>> > >>>> I have a web page I am developing. > >>>> > >>>> It has images embedded in it. > >>>> > >>>> The src attribute is ./?tag=guitar&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 >