treeleaf20 Posted January 26, 2011 Share Posted January 26, 2011 All, I found the following script to do the download: $resultsetpic = mysql_fetch_array($resultpic); $filename = "full_size/$resultsetpic[filename]"; // don't accept other directories $size = @getimagesize($filename); $fp = @fopen($filename, "rb"); if ($size && $fp) { header("Content-type: {$size['mime']}"); header("Content-Length: " . filesize($filename)); header("Content-Disposition: attachment; filename=$filename"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); fpassthru($fp); exit; } This downloads the file fine. However what I would like to do is also refresh the page that the user was just on. So I tried to add this: $resultsetpic = mysql_fetch_array($resultpic); $filename = "full_size/$resultsetpic[filename]"; // don't accept other directories $size = @getimagesize($filename); $fp = @fopen($filename, "rb"); if ($size && $fp) { header("Content-type: {$size['mime']}"); header("Content-Length: " . filesize($filename)); header("Content-Disposition: attachment; filename=$filename"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); fpassthru($fp); exit; } $target = "work_queue.php"; header("Location:". $target); However, this doesn't reload the page they were on. Any ideas on how to do this? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/225698-download-photo-with-a-header-redirect/ Share on other sites More sharing options...
_DarkLink_ Posted January 26, 2011 Share Posted January 26, 2011 Try: header("Refresh: 0;url=$target"); Link to comment https://forums.phpfreaks.com/topic/225698-download-photo-with-a-header-redirect/#findComment-1165350 Share on other sites More sharing options...
treeleaf20 Posted January 26, 2011 Author Share Posted January 26, 2011 Unfortunately, that didn't do the trick. Any other ideas? Link to comment https://forums.phpfreaks.com/topic/225698-download-photo-with-a-header-redirect/#findComment-1165445 Share on other sites More sharing options...
PFMaBiSmAd Posted January 26, 2011 Share Posted January 26, 2011 The file that dynamically outputs the headers, followed by the file contents CANNOT do anything else. It simply won't work. If you want to do anything on the page where the download link was at, you need to do it on that page, not in the download code. See the following topic for a possible way you can both trigger a download and do something on the originating page - http://www.phpfreaks.com/forums/php-coding-help/form-reload-problem/msg1516679/#msg1516679 Link to comment https://forums.phpfreaks.com/topic/225698-download-photo-with-a-header-redirect/#findComment-1165450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.