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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?