I wrote this code and save it in pic1.php
<?php
$path = "http://mysite.com/test.png";
header('content-type: image/png');
header ('Cache-Control: no-cache, no-store, max-age=0, s-maxage=0, must-revalidate');
header ('Cache-Control: post-check=0, pre-check=0', false);
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Pragma: no-cache');
$fgc = file_get_contents ($path);
print $fgc;
?>
and also wrote this code and saved it in pic2.php
<html>
<body>
<h4>title1</h4>
<img src="pic1.php" />
</body>
</html>
but when I open pic2.php by browser, I can not see any image
and when open pic1 I just see a blank page
please somebody help me...whats the wrong?
mlseim
01-31-2012, 10:59 PM
Can you tell us what the point of doing this is?
Are you trying to display the image without showing the file location?
I think PHP GD might be the better approach.
>ssp-cdr<
01-31-2012, 11:01 PM
Assuming the HTTP headers are correct, since you are passing a filename to file_get_contents() have you made sure that fopen wrappers have been enabled? Check the note about that here - http://ca3.php.net/manual/en/function.file-get-contents.php
mlseim
01-31-2012, 11:04 PM
Using GD:
<?php
$path = "http://mysite.com/test.png";
$img = imagecreatefrompng($path); // open image
// output image to browser
header("Content-type: image/png");
imagePng($img);
// clear memory
imagedestroy($img);
?>
.
hi thanks for the answe
I removed the empty lines before "<?php" in file pic1.php and it works now!
my actual code (in pic1) is this:
<?php
include("../config.php");
check_log();
global $db;
if(!sizeof($_GET))
{
$t=user_type();
if(class_exists($t))
{
$pic=new $t();
$pic=$pic->custome_find("personal_code",user_name(),1);
$image=base64_decode($pic->get_value('picture'));
if(strlen($image)>100)
print $image;
else
print file_get_contents(dirname(__FILE__)."/def_pic.png");
}
else
print file_get_contents(dirname(__FILE__)."/def_pic.png");
}
else
{
$t=$_GET['type'];
$id=$_GET['id'];
$pic=new $t();
$pic=$pic->custome_find("id",$id,1);
$image=base64_decode($pic->get_value('picture'));
if(strlen($image)>100)
print $image;
else
print file_get_contents(dirname(__FILE__)."/def_pic.png");
}
?>
but for this code didn't work.
for test if I replace this line (line 20)
print file_get_contents(dirname(__FILE__)."/def_pic.png");
with this:
{
$path = 'http://mysite.com/def_pic.png';
header('content-type: image/png');
header ('Cache-Control: no-cache, no-store, max-age=0, s-maxage=0, must-revalidate');
header ('Cache-Control: post-check=0, pre-check=0', false);
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Pragma: no-cache');
$fgc = file_get_contents ($path);
print $fgc;
}
but it didn't work...
( I sure the code in that line works becuase I tested it with a sample code
print "sample text"
)
The reson of second error was "include file!"..becuase I saved it with UTF-8!