Closed Thread Icon

Topic awaiting preservation: Problem displaying image files when running php locally Pages that link to <a href="https://ozoneasylum.com/backlink?for=25852" title="Pages that link to Topic awaiting preservation: Problem displaying image files when running php locally" rel="nofollow" >Topic awaiting preservation: Problem displaying image files when running php locally\

 
Author Thread
robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 05-24-2005 21:33

Hello everyone!

I have been designing my own php driven website for some time, and I am now interested on setting up a testing server on my computer.

I finally got php and mysql installed and working with apache.

I have my own "site engine" set up, so all the file requests handled by Apache are redirected through my php script. I then process them (convert urls, generate pages, etc), and send them back to Apache to be sent to the browser.

The problem I am having is that image files aern't being displayed.
The code i am using to open the image file is:

code:
header("X-Powered-By: ATIServer/Static");
header('Cache-Control: public, max-age=604800, must-revalidate');
header('Expires: '.gmdate('D, d M Y H:i:s',time()+604800).' GMT');
header("Content-Type: {$_SERVER['FAKE_EXT']['mime']}");

$f = @fopen($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'],"rb");
while (!feof($f)) {
echo fread($f, 8192);
}
fclose($f);
exit();



For other static files (css, js, etc) it works perfectly. For image files, the browser displays an "this image contains errors" message.

I think that the problem must have something to do with the fact that the image files are larger than the other files. Do you think it would truncate them, or something?
Is there some setting in Apache or php's .ini file that would make this work?

P.S. Don't ask about the $_SERVER['FAKE_EXT'] :-) That has already been set up by my site engine :-)

Thanks,

-Robur

------ edit ------

Just thought I might add that I am using PHP version 5, MySQL Client Version 5.0.1, and Apache version {whatever the default apache version that comes bundled with mac os X.3.9 is (think its 1.something)}.

(Edited by robur on 05-24-2005 21:43)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-24-2005 21:52

fread reads to the end of the line and quits which doesn't really work with binary files.


Instead use fpassthru


$f = @fopen($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'],"rb");
fpassthru($f);
fclose($f)
exit();



.:[ Never resist a perfect moment ]:.

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 05-24-2005 22:24

Hmm...

$f = @fopen($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'],"rb");
fpassthru($f);
fclose($f);

fpassthrough worked the same as what I had before...

I thing fread only works as you said when you omit the second parameter.

The problem must lie somewhere else.

Possibly a memory limit, or something? I am not an expert at this so please forgive me if I ask unintelligent questions :-)

Thanks anyway,

-Robur

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-24-2005 22:57

What does:
$_SERVER['FAKE_EXT']['mime']


That turn into? And for what type of file?



.:[ Never resist a perfect moment ]:.

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 05-24-2005 23:06

I said not to ask :-)

for a .png file, $_SERVER['FAKE_EXT']['mime'] = 'image/png';

-Robur

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 05-24-2005 23:42

I Solved it!

The problem I was having had nothing to do with the code that actually sent the file, that worked perfectly.

I finally traced the problem to the fact that I had included my configuration file several lines earlier with the include_once function.

The configuration file DID NOT OUTPUT anything. All it did was set several lines to an array. I replaced the include line in my main file with the contents of my configuration file, and it now works perfectly!

What was wrong before? I am still trying to figure that out myself. All I have thought of so far is that there is a bug in php5 which outputs some character which messes up images whenever you try to include a file. Sounds like a wild conspiracy theory, doesn't it? Well, if anyone can think of a different scenario, I would be glad to hear it!

Hope this helps someone else avoid all the debugging I had to endure :-)

-Robur

(Edited by robur on 05-25-2005 03:33)

« BackwardsOnwards »

Show Forum Drop Down Menu