如何在PHP文件路径中进行文件下载保存在数据库中

时间:2013-12-03 14:44:35

标签: php mysql file download

我是发展领域的新人,所以对愚蠢的问题抱歉。 我正在创建一个上传pdf文件并存储在目录中的脚本admin / uploads我在数据库中存储文件路径我的完整代码如下:
    

$image="uploads/".$_FILES['image']['name'];
$pdf="uploads/".$_FILES['pdf']['name'];
mysql_query("insert into novels                 values('','$title','$author','$image','$pdf','$body','$Keywords',$cat)");
header("location:add-novel.php?cat=$cat");
?>

我的表格是:

<form method="post" action="store-novel.php?cat=<?php echo $_REQUEST['cat'];?>"         enctype="multipart/form-data">
<table width="500" border="0"  align="left" class="innerTable">
<tr>
<td colspan="2" class="th">ADD NEW NOVEL</td>
</tr>

<tr>
<td>Title</td>
<td><input type="text" name="title" id="title" /></td>
</tr>
<tr>
<td>Author</td>
<td><input type="text" name="author" id="author" />
<!--<input type="hidden" name="category" value="<?php echo $_REQUEST['cat'];?>" />-->
</td>
</tr>
<tr>
<td>Image</td>
<td class="button"><input type="file" name="image" id="image" /></td>
</tr>
<tr>
<td>PDF</td>
<td><input type="file" name="pdf" id="pdf" /></td>
</tr>
<tr><td>post body</td>
<td><textarea name="body" id="body" cols="30" rows="15"></textarea></td>
</tr>
<tr>
  <td>Keywords</td>
  <td><input type="text" name="Keywords" id="Keywords" /></td>
</tr>
<tr><td></td><td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>

我想要一个用户可以下载我的pdf文件的下载页面

1 个答案:

答案 0 :(得分:1)

您想下载存储在服务器上的文件吗?

试试这个:

  

$ size = filesize($ yourfile);

     

header(“Content-Type:application / octet-stream”);

     

header(“Content-Disposition:attachment; filename ='$ filename'”);

     

标题(“Content-Length:$ size”);

     

的ReadFile($ yourfile);

相关问题