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');
}
?>