Jump to content

Download Photo with a Header Redirect


treeleaf20

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.