readfile

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fabaroa
Forum Newbie
Posts: 2
Joined: Tue Jul 20, 2010 3:12 pm

readfile

Post by fabaroa »

I am doing a simple look up and display file. I want to use POST for more security. to display the file I use readfile and the Content-Disposition: inline heading parameter. when I make this call in the same window no problem but when I open a new window I just get a little image as if it did not load. any suggestions? Here is some code:
This one Works
<form name='myform' action='readfile2.php' method='post'>
<input type=hidden name='doc_id' value=''>
<input type=hidden name='fileID' value=''>
<input type=hidden name='tab' value=''>
<input type=hidden name='cab' value=''>
<input type=hidden name='ID' value=''>
<input type=hidden name='download' value='0'>
<input type=hidden name='filename' value=''>
<input type=hidden name='delete' value='0'>
<input type=hidden name='tmp' value=''>
</form>
... read sql get full path
$headerArr = array (
'Content-type: '.$type,
'Content-Length: '.$fsize,
'Cache-Control:',
'Pragma:',
'Content-Disposition: inline; filename="'.$headerFName.'"',
);

ini_set('zlib.output_compression', 'Off');
foreach($headerArr as $myHeader) {
header($myHeader);
}
readfile($finalPath);
****************************
and this one doesnt work:
<form name='myform' action='readfile2.php' method='post' target='blank'>
<input type=hidden name='doc_id' value=''>
<input type=hidden name='fileID' value=''>
<input type=hidden name='tab' value=''>
<input type=hidden name='cab' value=''>
<input type=hidden name='ID' value=''>
<input type=hidden name='download' value='0'>
<input type=hidden name='filename' value=''>
<input type=hidden name='delete' value='0'>
<input type=hidden name='tmp' value=''>
</form>
... read sql get full path
$headerArr = array (
'Content-type: '.$type,
'Content-Length: '.$fsize,
'Cache-Control:',
'Pragma:',
'Content-Disposition: inline; filename="'.$headerFName.'"',
);

ini_set('zlib.output_compression', 'Off');
foreach($headerArr as $myHeader) {
header($myHeader);
}
readfile($finalPath);
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

Re: readfile

Post by LuaMadman »

Just did a quick look...
You don't say that you get a new window or not.
I'm guessing you don't get a new wndow, and instead you get the little image as if it did not load.
Anyway, what caught my eye, was the target. target="blank" tells html to open a frame named blank, target="_blank" tells it to open a new window.
fabaroa
Forum Newbie
Posts: 2
Joined: Tue Jul 20, 2010 3:12 pm

Re: readfile

Post by fabaroa »

I do get a new window, just not the image although I get a little image box. If I change Content Disposition to attachment I get the correct image. Problem is I want to display it. I also just notice this only happens with tif files.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: readfile

Post by Jade »

Try adding:

Code: Select all

header('Content-type: image/tiff');
Post Reply