我已将文件上传到MySQL数据库,但在检索时我遇到了问题。
的download.php
<?php
$host="localhost";
$username="root";
$password="";
$db_name="application";
$con=mysqli_connect("$host", "$username", "$password","$db_name")or die("Your Connection is in error");
$a =$_GET['contactid'];
$query = "SELECT filename,filetype,filesize,filecontent FROM contact WHERE contactid = '$a' ";
$result = mysqli_query($con,$query) or die('Error, query failed');
list($filename, $filetype, $filesize, $filecontent) = mysqli_fetch_array($result);
header("Content-length: $filesize");
header("Content-type: $filetype");
header("Content-Disposition: attachment; filename=$filename");
echo $filecontent;
exit;
?>
我从上一个屏幕获得的$ a无效。相反,如果我给contactid = 18 ..文件正在下载。
上一个screen.php
$GET =mysqli_fetch_array(mysqli_query($con,"SELECT contactid,groupname,firstname,lastname,mobile1,mobile2,email1,email2,city,country,designation,companyname,address1,address2,district,pincode,website,others,filename FROM contact WHERE contactid='$a'"));
$contactid = $GET['contactid'];
$filename = $GET['filename'];
<a href='download.php?contactid=".$contactid."'><?php echo $filename;?> </a>
答案 0 :(得分:1)
<a href='download.php?contactid=".$contactid."'><?php echo $filename;?> </a>
使用两个php变量$contactid
和$filename
的上述语句。您有echo
$filename
但忘了回复$contactid
。如果上述陈述不在PHP
标签内。那应该是,
<a href='download.php?contactid=<?php echo $contactid ?>'><?php echo $filename;?> </a>
如果它在PHP
标签内,则应该是,
echo "<a href='download.php?contactid=".$contactid."'>".$filename."</a>";
答案 1 :(得分:0)
使用
"...... where contactid='".$a."'";