Re: download file from an ajax request

From: Date: Fri, 20 Jun 2008 12:25:43 +0000
Subject: Re: download file from an ajax request
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-275688@lists.php.net to get a copy of this message
On Fri, Jun 20, 2008 at 8:02 AM, pere roca <peroc79@gmail.com> wrote: > > hi everybody! > > Hi! > > is there some way to allow downloading a PHP generated file from an ajax > request? > the simple code below generates the image but not prompts the "save or open > file..." (it works if I call it directly, not from an HTML and using > ajax...) > > thanks, > Pere > > $layer=$_GET['params']; //coming from ajax request > $image0="yÕkÇåm"Є7+Wp > §http://edit3.csic.es/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".$layer."&STYLES=&format=image/png&bbox=-9.65,35.6,4.85,43.85&WIDTH=760&HEIGHT=380&SLD=http://edit.csic.es/fitxers/sld/pou.sld"; > $image=imagecreatefrompng($image0); > imagepng($image,'definitius_hola.png'); > > //Opens file or URL > $h = fopen("definitius.png", "r"); > header("Content-Type: image/png"); > header("Content-Disposition: attachment; filename=\"definitius.png"); > fpassthru($h); > fclose($h); > -- > View this message in context: >http://www.nabble.com/download-file-from-an-ajax-request-tp18028188p18028188.html > Sent from the PHP - General mailing list archive at Nabble.com. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > The only thing I can think of is using JS to create some sort of IFRAME, meta redirect, window.location, or a popup window, something that will force the page to hit your download script directly. I've never attempted it myself so I'm not sure what sort of issues IE would have with any of the above.

« previous php.general (#275688) next »