我是开发领域的新手,所以提前对愚蠢的问题表示抱歉。
我正在创建一个上传 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 文件
最佳答案
您想下载服务器上存储的文件吗?
试试这个:
$size = filesize($yourfile);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='$filename'");
header("Content-Length: $size");
readfile($yourfile);
关于php - 如何在php中使文件下载仅将文件路径保存在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20354205/