Jump to content

Archived

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

Chips

bug with my downloads script? *FIXED*

Recommended Posts

Fixed, appears to be an issue with a password protected directory. Running this script to download a file that is not located inside the directory works.


I am having an issue, that I cannot seem to resolve!
Essentially, click on the downloads link and it all comes up with the open/save prompt. If you download any of the files, though, it says it's corrupted?
My max filesize in php.ini IS big enough to cope by far (test files range from 25kb to 655kb, and the max size is 2Mb!), and I am using firefox.

[code]$array = mysql_fetch_array($query, MYSQL_ASSOC);
                  $file = $_SERVER['DOCUMENT_ROOT'] . '/newsite/' . $array['download'];
                  header('Cache-Control: no-store, no-cache, must-revalidate');
  header('Cache-Control: post-check=0, pre-check=0', FALSE);
      header('Pragma: no-cache');
                  header('Content-Description: File Transfer');
  header('Content-Type: octet-stream');
                  header('Content-Type: application/force-download');
                  header('Content-Length: ' . filesize($file));
                  header('Content-Disposition: attachment; filename=' . basename($file));
  header("Content-Transfer-Encoding: binary");
                  readfile($file);
[/code]
Now the document root isn't an issue, if i comment out the headers and just do
[code]
echo $file;
[/code]
then it shows the correct root path for the server to the file.
When you download, it does prompt with the right filename etc, and when downloaded - it's the right size too.

Error messages are (zip file being used, contents are 5 php files).
[quote]
The archive is either in unknown format, or damaged[/quote]
or if you double click instead of using "extract here", it will open the extract window and say:
[quote]Unexpected end of archive[/quote], but shows the files and their sizes okay.

Anyone have any ideas as to what I am doing wrong/spot the bug that I am having?

Help would be much appreciated, downloads are integral to the site i have created, and everything else is working just fine :( Supposed to present either later today, or tomorrow - and would really like to remove the last few bugs.

If I use a pdf file to download instead, i get the following message:
"... could not open the file because it is either not supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)"
That is when trying to open the acrobat pdf file with the reader :(

Share this post


Link to post
Share on other sites

×

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.