Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP force download and refresh SOLUTION not working
    primarykey
    data
    text
    <p>End goal: Click link on page 1, end up with file downloaded and refresh page 1. Using PHP to serve downloads that are not in public html.</p> <p>Approach:</p> <p><strong>Page 1.</strong> Link transfers to page 2 with get variable reference of which file I am working with. </p> <p><strong>Page 2.</strong> Updates relevant SQL databases with information that needs to be updated before refresh of page 1. Set "firstpass" session variable. Set session variable "getvariablereference" from get variable. Redirect to page 1.</p> <p><strong>Page 1.</strong> If first pass session variable set. Set Second pass session variable. Unset first pass variable. Refresh Page. On reload the page will rebuild using updated SQL database info (changed on page 2.).</p> <p><strong>Refreshed Page 1.</strong> If second pass session variable set. Run download serving header sequence.</p> <p>This is page 1. I am not showing the part of page 1 that has the initial link. Since it doesn't matter.</p> <pre><code>// REFERSH IF FIRSTPASS IS LIVE if ($_SESSION["PASS1"] == "YES"){ $_SESSION["PASS1"] = "no"; $_SESSION["PASS2"] = "YES"; echo "&lt;script&gt;document.location.reload();&lt;/script&gt;"; } if ($_SESSION["PASS2"] == "YES"){ // Grab reference data from session: $id = $_SESSION['passreference']; // Serve the file download //First find the file location $query = "SELECT * from rightplace WHERE id = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $filename = $row['file']; $uploader = $row['uploader']; // Setting up download variables $string1 = "/home/domain/aboveroot/"; $string2 = $uploader; $string3 = '/'; $string4 = $filename; $file= $string1.$string2.$string3.$string4; $ext = strtolower (end(explode('.', $filename))); //Finding MIME type if($ext == "pdf" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: application/pdf'); readfile($file); } if($ext == "doc" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: application/msword'); readfile($file); } if($ext == "txt" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: text/plain'); readfile($file); } if($ext == "rtf" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: application/rtf'); readfile($file); } if($ext == "docx" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); readfile($file); } if($ext == "pptx" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: application/vnd.openxmlformats-officedocument.presentationml.presentation'); readfile($file); } if($ext == "ppt" &amp;&amp; file_exists($file)) { header("Content-disposition: attachment; filename= '$filename'"); header('Content-type: application/vnd.ms-powerpoint'); readfile($file); } } </code></pre> <p>The script on page 2 is working correctly. It updates the sql database and redirects to the main page properly. I have also checked that it sets the "$_SESSION['passreference'];" correctly and nothing on page 1 would unset it.</p> <p>So, thats the whole long explanation of the situation. I am stumped. What happens is, as I said page 2 works fine. Then it kicks to page 1, refreshes and then doesnt push any download. I know that the download script works and that the files are there to be downloaded (checked without the whole refresh sequence).</p> <p>I essentially have two questions:</p> <ol> <li><p>Can anyone spot whats going wrong?</p></li> <li><p>Can anyone conceptualize a better approach?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload