Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts

    Error during Safari readfile() download

    Hey everyone,

    I'm writing a secure file download system and it works fantastically except for safari users.

    I have had several points of feedback saying that when they download a zip file via safari it locates the file and shows that it should start downloading but doesnt, resulting in a 0-filesize zip.

    I'm using the code below for the actual download, do you have any idea what could be causing the issue?

    The $filename is set earlier in the script but just for arguments sake, lets assume it's, myfiles.zip

    PHP Code:
    $path "http://www.root.com/".$filename;
    header("Pragma: public");
    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-Length: " .(string)(filesize($path)) );
    header('Content-Disposition: attachment; filename="'.basename($path).'"');
    header("Content-Transfer-Encoding: binary\n");

    readfile($path); // outputs the content of the file 

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Your Monitor
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by YourDirector View Post
    PHP Code:
    $path "http://www.root.com/".$filename//This is a problem.

    header("Content-Length: " .(string)(filesize($path)) );
    header('Content-Disposition: attachment; filename="'.basename($path).'"');

    readfile($path); // outputs the content of the file 
    Every time you refer to path, you're referring to a url. You're not using cURL to get the details such as the filesize, so what do you think your php script will output for a filesize? - Probably 0 as it has no way of knowing.

    Also look at the filename in the content-disposition header - you're giving the file a url as a name. Finally you're trying to output a file directly from a url.

    All of those $path variables should relate to the file on file system.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts