dousuowu4610 2015-12-04 14:45
浏览 54

我网站上的下载功能中的Readfile错误

Hi i am making a download feature on my website and it is running however all the files are corrupted due to a recurring error readfile(): Filename cannot be empty in 'my/file/location' I don't understand why this is happening because according to every post I have looked at I am doing the download->zipfiles procedure correctly. Please help.

By the way i think the key to the answer may be in the fact that when i open the zip in a text file it reads:


Warning: file_get_contents(/uploads/): failed to open stream: No such file or directory in /home/ghostx19/public_html/phDownloader.php on line 21

the error is repeated 10 times because of the loop obviously

My Code:

 <?php 
 //define stuff
$dir = "./uploads";
$allfiles = glob($dir.'*.{aiff}', GLOB_BRACE); 

// create zip
$zip = new ZipArchive();
$zip_name = "zipfile.zip";
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){
    $error .= "* Sorry ZIP creation failed at this time";
}



//array of random files    
$n=1;
while ($n<=10){
$n ++;
$randomfile = $allfiles[array_rand($allfiles)];
$path = "./uploads".$randomfile;
$zip->addFile(basename($path),  file_get_contents($path)); 
}

// //present for download
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zip_name);
readfile('zipfile.zip');
  if(file_exists('zipfile.zip'))
{
  unlink('zipfile.zip');
}

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP