-1

For my own website I want to have a page where you can download .rar files from. However when I download and open the file. I get a message box saying: "No archives found.".

I dont know what to do, this is my code.

$filename="inputValidatorCasd.rar";
$file="c:\\wamp\\www\\DennisWeb\\Files\\$filename"; 
$len = filesize($file);  
ob_clean(); 
header("Pragma: public");
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Cache-Control: public"); 
header("Content-Description: File Transfer");
header("Content-Type:application/octet-stream"); 
$header="Content-Disposition: attachment; filename=$filename;"; 
header($header); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".$len);  
@readfile($file); 
exit;
Gerald Schneider
  • 17,002
  • 9
  • 57
  • 77

1 Answers1

-2

You can use following method to download RAR file :-

$album_name = "testing"
$files = array("1.txt", "2.txt"); // array of your files

$zip = new ZipArchive();

# create a temp file & open it
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE);

# loop through each file
foreach($files as $file){

    # download file
    $download_file = file_get_contents($file);

    #add it to the zip
    $zip->addFromString(basename($file),$download_file);

}

# close zip
$zip->close();

# send the file to the browser as a download
header('Content-disposition: attachment; filename='.$album_name.'.rar');
header('Content-type: application/zip');
readfile($tmp_file);

It may help you.

Harsh Sanghani
  • 1,654
  • 1
  • 11
  • 32