I don't know if this is the correct way but you can do it by making an action

public function downloadAction()
{
  /* get here all the data you need from the database
   * $size = size of the file you can get by readfile()
   * $filename = 12f3f1aa1b11ec11dd1dd1.zip (with the path)
   * $filename1 = example.zip
 */

  if(file_exists($filename)) {
    ob_start();
    $size = readfile($filename);
    $this->view->data = ob_get_clean();
  }

  header('Expires: Mon, 20 May 1974 23:58:00 GMT');
  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  header('Cache-Control: no-store, no-cache, must-revalidate');
  header('Cache-Control: post-check=0, pre-check=0', false);
  header('Cache-Control: private');
  header('Pragma: no-cache');
  header("Content-Transfer-Encoding: binary");
  header("Content-type: binary/octet-stream");
  header("Content-length: {$size}");
  header("Content-disposition: attachment; filename=\"{$filename1}\"");

  $this->_helper->layout()->disableLayout();
  $this->render('download');
}

make a view file (download.phtml) with this:

<?php echo $this->data; ?>


krazen wrote:
> 
> Hello.
> 
> How can I make my Zend application download file from other server (given
> URL) to local server and save it in given directory and automatically
> rename it?
> 
> How can I make my Zend app return binary data?
> E.g. example.zip has ID 1000 in my application's database and  I want my
> app to return example.zip when I type in my address bar
> http://localhost/file/download/id/1000
> Should I do it by using redirection?
> 
> I want my files to have unique names, like 12f3f1aa1b11ec11dd1dd1.zip and
> keep in db that this file's original name is example.zip, and when users
> will try to download it I want it to return file named example.zip
> 
> I hope I didn't wrote it in too complicated way and somebody will
> understand and be able to help me :)
> 
> Greetings
> 
> 
> 


-----
visit my website at  http://www.phpscriptor.com/ http://www.phpscriptor.com/ 
-- 
View this message in context: 
http://www.nabble.com/Two-questions-about-file-handling-in-Zend-tp21388164p21390237.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to