Page 1 of 1

PHP File-link Problem

Posted: Thu Aug 13, 2009 5:55 pm
by apease11
every time. Here's my working and not working code:

Working:

Code: Select all

if ($checkbox) {
      $file = 'http://12.148.233.90/downloads/Tutorial1.wmv.zip';
      // Set headers
      header("Cache-Control: public");
      header("Content-Description: File Transfer");
      header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip");
      header("Content-Type: application/zip");
      header("Content-Transfer-Encoding: binary");
      //header("Content-Length: " . filesize($file));
      ob_clean();
      flush();
      readfile("$file");
      exit;
      }
      else {
              ...
      }
Not working, but want to work:

Code: Select all

if ($checkbox) {
      $file = '/downloads/Tutorial1.wmv.zip';
      // Set headers
      header("Cache-Control: public");
      header("Content-Description: File Transfer");
      header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip");
      header("Content-Type: application/zip");
      header("Content-Transfer-Encoding: binary");
      header("Content-Length: " . filesize($file));
      ob_clean();
      flush();
      readfile("$file");
      exit;
      }
      else {
              ...
      }
With the not working code section, it says that it can't find the file. The reason I want that section working is because I want the file size to be correct when you download (so it doesn't say "Unknown Time Remaining") and to simplify the code a little bit. Thanks for your help.

If you need me to clarify anything, just ask. I could also map my HDD and upload my IIS settings too.

Re: PHP File-link Problem

Posted: Fri Aug 14, 2009 2:52 am
by susrisha
Dont know if this might help but i found an example of the same in php manual
http://in3.php.net/readfile

Code: Select all

 
$file = 'monkey.gif';
 
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
 

Re: PHP File-link Problem

Posted: Fri Aug 14, 2009 3:24 am
by requinix

Code: Select all

'/downloads/Tutorial1.wmv.zip'
More familiar with Windows? That's the Unix equivalent of

Code: Select all

'C:\\downloads\\Tutorial1.wmv'
I'm sure that's not what you meant.

Try

Code: Select all

$_SERVER["DOCUMENT_ROOT"] . '/downloads/Tutorial1.wmv.zip'

Re: PHP File-link Problem

Posted: Fri Aug 14, 2009 8:45 am
by apease11
Setting

Code: Select all

$file = $_SERVER['DOCUMENT_ROOT'] . '/downloads/Tutorial1.wmv.zip';
brings me to a "Problem Loading Page" screen, Firefox's built in 404.