[Midas] redirect()

Mona Wong mona at sdsc.edu
Tue Jul 10 15:48:41 EDT 2012


Hi Zach:

	Thanks for the code!   It worked beautifully (:

cheers,
Mona


On Jul 10, 2012, at 11:13 AM, Zach Mullen wrote:

> Redirect is just sending an HTTP redirect to a different controller.  The best example of how to download a file to the client can be seen in core/controllers/components/DownloadBitstreamComponent::download.
> 
> Your version will probably be simpler; you will just set the appropriate headers for Content-Type (set to, for example "image/jpeg" or "image/png", whatever your image MIME type is).  Set the other headers as you wish (such as Content-Length, Cache-Control, Expires, Content-Disposition.  When you are ready to send the actual bytes, you'll need to flush any output buffering that happens using the following block:
> 
> while(ob_get_level() > 0)
>       {
>       ob_end_clean();
>       }
> 
> Then open your file and send it to the user, like so:
> 
> $chunkSize = 1024*1024; // 1 MiB chunk written to buffer at a time
> $fh = fopen('path_to_file.png', 'rb'); //use the actual path to the file :)
> while(!feof($fh) && connection_status() == 0)
>   {
>   echo fread($fh, $chunkSize); //read a chunk and send it to the client
>   }
> fclose($fh);
> 
> exit();
> 
> The exit() call obviously should only be done after all your required logic is finished, but it is necessary within Zend framework to avoid header-after-output errors.
> 
> My understanding is that you are just downloading a temporary file and then deleting it, is this correct?
> 
> -Zach

*********************************************
    Mona Wong
    Web & iPad Application Developer
    San Diego Supercomputer Center

    "Forgive everyone everything."
				-- Regina Brett
*********************************************







More information about the Midas mailing list