albatom7@hotmail.com Posted July 26, 2010 Share Posted July 26, 2010 Hi everyone ! First of all thanks for all the help in advance ! I'm trying to force the download of png files for a websites. It works perfectly with Firefox but not with Safari (nothing happening when clicking) and Chrome (file corrupted). I looked everywhere on internet for a fix but didn't find any working solutions ! Please find below my code : ob_end_clean(); //header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); //header("Content-Type: application/download"); header("Content-Transfer-Encoding: Binary"); header('Accept-Ranges: bytes'); header ("Content-Disposition: attachment; filename=".basename($_REQUEST['path']).";"); header("Content-Description: File Transfer"); header('Expires: 0'); header('Pragma: public'); header("Content-Length: ".$filesize($_REQUEST['path'])); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Connection: close"); readfile($_REQUEST['path']); Best, Quote Link to comment Share on other sites More sharing options...
albatom7@hotmail.com Posted July 27, 2010 Author Share Posted July 27, 2010 No one inspired ? :'( I know that this problem seems solved already but in my case I tried every fixed I could find on the web and nothing worked. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted July 27, 2010 Share Posted July 27, 2010 not sure why it would corrupt, but with the content disposition it SHOULD force download either way, you could try setting the content-type as image/png because google chrome has a weird database type security system, and it encrypts everything it receives, and if it receives it as something it isn't it could be causing the corruption, (the db structure I'm referring to is it's cache, not sure why it would affect a download.. but, try it anyway doesn't hurt ) Quote Link to comment Share on other sites More sharing options...
albatom7@hotmail.com Posted July 27, 2010 Author Share Posted July 27, 2010 Thanks for the reply. I had the same though and then tried this solution but same problem... I think there is something wrong with the filesize because chrome force the download but the file is 0kb. Again for Safari nothing happens at all. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted July 27, 2010 Share Posted July 27, 2010 very good catch.. you're using filesize as a variable I know its possible to do that but in this case you'd want to drop the $ EDIT: For anybody who looks @ this what I meant by filesize as a variable: http://www.php.net/manual/en/functions.variable-functions.php for example: <?php $filePath = '....'; $filesize = 'filesize'; $filesize($filePath); ?> but since you didn't specify the function to the variable it won't work lol but disregard the above if you aren't interested <33 Quote Link to comment Share on other sites More sharing options...
albatom7@hotmail.com Posted July 27, 2010 Author Share Posted July 27, 2010 I'm ashamed .... Well It works for Chrome ! Still have the problem in Safari but I think it s connected to a javascript problem that I can fix. Thanks again anyway !!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.