Header Location + Content Placement

So, I have a download page where you click on the link, it opens / downloads / download / randomhash

randomhash is in db, I increment the download counter and then redirect to the actual file, e.g. / uploads / 2012 / file.png.

Everything works, except that the redirection does what I would like to do. I'm not sure why it is not working ...

header("Location: " . $row->uri); header("Content-Disposition: attachment; filename=$row->name"); 

The first time the file is uploaded, it has the corresponding content header (in firebug), but it does not ask for the file to be downloaded (what does it need, right?). Any ideas?

Answer headers:

 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public Connection: Keep-Alive Content-Disposition: attachment; filename=promotion_photo_2.jpg Content-Encoding: gzip Content-Length: 20 Content-Type: text/html; charset=utf-8 Date: Mon, 27 Feb 2012 01:01:22 GMT Expires: Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: timeout=5, max=100 Location: /uploads/2012/mediakitD3CF.jpg Pragma: no-cache Server: * Vary: Accept-Encoding X-Powered-By: * X-UA-Compatible: IE=Edge,chrome=1 
+3
source share
1 answer

You set the Content-Disposition header in the same answer that tells the browser where to redirect. My suggestion is to simply pass the attachment to the answer, without redirecting

 header('Content-Disposition: attachment; filename=file-to-be-downloaded.jpg'); header('Content-type: image/jpeg'); // or what is relevant, ie application/octet-stream $fn=fopen("path-to-file/file-to-be-downloaded.jpg","r"); fpassthru($fn); 
+4
source

All Articles