Jump to content

Archived

This topic is now archived and is closed to further replies.

RiposoEterno

Viewing an image with fpassthru and fopen problem

Recommended Posts

Hey guys, i'm having problem with a php script of mine.

Basically it's opening and image and displaying it back to the browser (I don't want people to see the real location of the image).

The problem is, instead of displaying me back an image, when I go to the script it displays to me the page url and a blank view source. This is what I see: http://localhost/upload/scrview.php?fid=ZHBlcyBvdCB3cHJs.jpg

ALSO, when I view page info, it's the right file size and the right mime type (image/jpeg), but doesn't display any image! and if I save page it saves it as a jpeg that when opened has no image, "preview not available".

Things you should know before you read the script:

the get_image_data function i have does work and gives back the right mime type
Also, this may be interesting, but if I remove the headers I do see the dump of the image file.

Please ignore anything in there that you don't know what it is, I can assure you that the file is being opened (like i said if i remove the header functions i see the image data dump).

[code]
<?php


require_once('ipb_integrator.php');
global $ipsclass, $DB;


$file = $_REQUEST['fid'];
$loc = $ipsclass->vars['upload_dir']."/dls/dlscrs/";
$img = $IPBI->get_image_data($loc.$file);
$fp = fopen(ROOT_PATH."/uploads/dls/dlscrs/".$file, 'rb');
if ($fp)
{
header("Content-Type: ".$img['mime']);
header("Content-Length: ".filesize($loc.$file));
fpassthru($fp);
exit;
}
else
{
echo "shite";
}

?>
[/code]

Share this post


Link to post
Share on other sites
my code, that i've never had a problem w/

[code] 
$filename = "theFile.jpg"
$filePath = "hiddenPhotoDirectory/photos/".$filename;

  header('Content-type: image/jpeg');
  header("Content-Disposition: inline; filename=".$filename);
  readfile($filePath);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.