2012-06-10 3 views
0

Я пытаюсь загрузить несколько файлов в zip-архиве с помощью PHP/codeigniter. Этот код работает на моем localhost, но на веб-хосте запускается zip, но файлы не добавляются в zip-файл. Это ошибка, я получил:php ZipArchive readfile error Нет такого файла или каталога ziparchive

A PHP Error was encountered 

Severity: Warning 
Message: readfile(Album1.zip): failed to open stream: No such file or directory 
Filename: controllers/download.php 
Line Number: 54 

Это мой код:

function _zipFilesAndDownload($file_names,$archive_file_name,$file_path) 
    { 

     $zip = new ZipArchive(); 

     if(file_exists($archive_file_name)){ 
      if ($zip->open($archive_file_name, ZIPARCHIVE::OVERWRITE)!==TRUE) { 
      exit("cannot open <$archive_file_name>\n"); 
      } 
     }else 
     //create the file and throw the error if unsuccessful 
     if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE)!==TRUE) { 
      exit("cannot open <$archive_file_name>\n"); 
     } 
     //add each files of $file_name array to archive 
     foreach($file_names as $files) 
     { 
      $zip->addFile($file_path.$files,$files); 
      //echo $file_path.$files."<br>"; 
     } 
     $zip->close(); 
     //then send the headers to foce download the zip file 

     header("Content-type: application/zip"); 
     header("Content-Disposition: attachment; filename=$archive_file_name"); 
     header("Pragma: no-cache"); 
     header("Expires: 0"); 
     readfile("$archive_file_name"); 

     exit; 

    } 
    function album($albumid){  
      $this->load->model("albums_model"); 
      $this->load->model("songs_model"); 
      $aid = $albumid; 
      $albuminfo = $this->albums_model->getAlbum($aid); 
      $songs = $this->songs_model->getSongNamesAvailableDownload($aid); 
      $file_path=$_SERVER['DOCUMENT_ROOT']. '/demo/albums/'.$albumid.'/'; 
      $archive_file_name = $albuminfo->album_name; 
      $file_names = $songs; 
      $this->_zipFilesAndDownload($file_names,$archive_file_name,$file_path); 
    } 

ответ

0

CodeIgniter обеспечивает zip library для этой цели. Это намного проще в обращении, и вы можете свести свой код к минимуму. Это может также решить вашу проблему. Удачи!

Смежные вопросы