Note that there are some explanatory texts on larger screens.

plurals
  1. POphp header question
    text
    copied!<p>I'm trying to mask my download links using the code below.</p> <p>It is <em>almost</em> working - it seems to get the file correctly however when it downloads the file is only 4kB in size.</p> <p>Can anyone offer any suggestions??</p> <p>Thanks!</p> <p>Also please let me know if you need any additional details - I'm running this on MAMP using FF3.5.13</p> <pre><code>&lt;?php $filename="download.zip"; $folder = 'downloads'; $abs_path = $_SERVER['DOCUMENT_ROOT']; $path = $abs_path . "/" . $folder ."/" .$filename; // the location of the file. $mm_type="application/zip"; //this is for .zip files - Change this for other file types. header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: " . $mm_type); header('Content-Disposition: attachment; filename="'.basename($path).'"'); header("Content-Length: " . filesize($path)); // **code edited as per comments below** header("Content-Transfer-Encoding: binary"); readfile($path); //Output file for download. exit(); ?&gt; </code></pre> <p>UPDATE: here is what is inside the file generated</p> <p><br /> <b>Warning</b>: filesize() [function.filesize]: stat failed for /Applications/MAMP/htdocs/downloads/download.zip in <b>/Applications/MAMP/htdocs/CURRENT/test.php</b> on line <b>15</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/CURRENT/test.php:15) in <b>/Applications/MAMP/htdocs/CURRENT/test.php</b> on line <b>15</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/CURRENT/test.php:15) in <b>/Applications/MAMP/htdocs/CURRENT/test.php</b> on line <b>16</b><br /> <br /> <b>Warning</b>: readfile(/Applications/MAMP/htdocs/downloads/download.zip) [function.readfile]: failed to open stream: No such file or directory in <b>/Applications/MAMP/htdocs/CURRENT/test.php</b> on line <b>17</b><br /></p>
 

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