dongzhi1851 2013-12-03 14:44
浏览 104
已采纳

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

I am new in the field of developement so advance sorry for stupid question. I am creating a script that upload pdf files and stored in a directory admin/uploads I am storing file path in database my complete code is as under:

$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");
?>

and my form is:

<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>

I want to a download page from where user can download my pdf files

  • 写回答

1条回答 默认 最新

  • dongpao1905 2013-12-03 14:51
    关注

    You want to download a file stored on the server?

    Try this:

    $size = filesize($yourfile);

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

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

    header("Content-Length: $size");

    readfile($yourfile);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题