2011-04-15 50 views

回答

1

你设置头 header("Content-Type: image/jpeg")

为了测试呼叫URL

getpicture.php?fid=1 

,并看看会发生什么?

编辑:在第5步

<? 
if(isset($_GET['fid'])) 
{ 
// connect to the database 
include "connect.php"; 

// query the server for the picture 
$fid = $_GET['fid']; 
$query = "SELECT * FROM files WHERE fid = '$fid'"; 
print $query; 
$result = mysql_query($query) or die(mysql_error()); 
print_r($result); 

// define results into variables 
$name=mysql_result($result,0,"name"); 
$size=mysql_result($result,0,"size"); 
$type=mysql_result($result,0,"type"); 
$content=mysql_result($result,0,"content"); 
print "check point 1 => $name, $size, $type, $content"; 
// give our picture the proper headers...otherwise our page will be confused 
header("Content-Disposition: attachment; filename=$name"); 
header("Content-length: $size"); 
header("Content-type: $type"); 
echo $content; 

mysql_close(); 
}else{ 
die("No file ID given..."); 
} 

?> 

替换上面的代码,并从浏览器中调用,看看它的打印?

+0

如你所说,我设置了标题中的形象,我测试的URL,但没有出现 – woninana 2011-04-15 05:53:31

+0

看到我上面的编辑。 – 2011-04-15 06:00:32

0

getpicture.php

  1. 得到图像的ID
  2. 查询数据库。
  3. 回声出后header("Content-Type: image/jpeg")