脚本宝典收集整理的这篇文章主要介绍了php – 标题下载文件已损坏,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我获取文件ID并调用下载函数的地方:(handleDownload.PHP)
if (isset($_GET['id'])) { $id = $_GET['id']; //pump id into function getDBFiles to pull file wITh matching id $fileData = $Download->getDBFiles($id); header('Content-tyPE:"' . $fileData[2]. '"'); header('Content-Disposition: attachment; filename="' . $fileData[1]. '"'); echo $fileData[0]; exit; }
public function getDBFiles($id) { global $database; $sql = "SELECT * From ".self::$table_name." WHERE resume_id ='" . $id . "'"; $result = $database->query($sql); if ($row = $result->fetch_array(MysqLI_ASSOC)) { $name = $row['resume_title']; $type = $row['file_type']; $content = $row['resume_data']; //content of file //$size = $row['file_size']; //file size return array($content,$name,$type); } } $Download = new Download(); $download =& $Download;
if (isset($_GET['id'])) { $id = $_GET['id']; MysqLi_select_db($con,"apples"); $query = "SELECT * From resume where resume_id ='" . $id . "'"; $result = MysqLi_query($con,$query) or die('Error,query Failed'); if ($row = $result->fetch_array(MysqLI_ASSOC)) { $name = $row['resume_title']; $type = $row['file_type']; $content = $row['resume_data']; //content of file $size = $row['file_size']; //file size header('Content-Type:"' . $type . '"'); //header('Content-length:"' . $size . '"'); header('Content-Disposition: attachment; filename="' . $name . '"'); //var_dump($row); echo $content; } }
更新:
我现在得到的下载文件已损坏,而不是空白文件.这是不同下载代码输出相同文件的方式.顶部的一个来自OOP代码,而另一个来自工作的非OOP版本.
这是我的完整下载代码.
try { //execute retrieval of files from database $Download-> showDBFiles(); //pass results to output array $output = $Download->getMessages(); //if id is set then get file from database if (isset($_GET['id'])) { $id = $_GET['id']; //pump id into function getDBFiles to pull file with matching id $fileData = $Download->getDBFiles($id); header('Content-Type:"' . $fileData[2]. '"'); header('Content-Disposition: attachment; filename="' . $fileData[1]. '"'); echo $fileData[0]; die(); } } catch (Exception $e) { $result[] = $e->getMessages(); }
<h2>Output</h2> <?PHP if ($output) { ?> <ul class="result"> <?PHP foreach ($output as $message) { $id = $message['id']; $name = $message['name']; ?> <li><a href="handleDownload.PHP?id=<?PHP echo $id; ?>"><?PHP echo $name; ?></a></li> <?PHP } ?> </ul>
以上是脚本宝典为你收集整理的php – 标题下载文件已损坏全部内容,希望文章能够帮你解决php – 标题下载文件已损坏所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。