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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.