SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File download is not working

    Hi,

    I'm using php 5.3 and Apache 2.2 in Linux OS. The file download is not working. I have used below code. Please help! The same code was working in local pc while developed. The local pc was php 5.3, apach2.2 and windows 7.

    header('Content-Description: File Transfer');
    //Below line is replace by force-download because this was not working when downloaded from web server
    //header('Content-Type: application/octet-stream');
    header("Content-Type: application/force-download");
    //header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Disposition: attachment; filename='.$actualfilename); //fetched filename from database
    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);

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I just test it and it is working for me.

    PHP Version 5.2.17

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for quick response. The code mentioned above is implemented in Annual Project. Can you please try below link and download the excel?

    http://www.annualproject.com/sourcec...8a9e8470367655

  4. #4
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I downloaded it and there is no file name associated with the download. Viewing it with excel shows no content.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's very strange... when I try to open it, it saves file with name as "0" and I cannot open it. I will try it again.

  6. #6
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Check your

    header('Content-Disposition: attachment; filename='.$actualfilename); //fetched filename from database

    make sure actualfilename is the name of the file name you want to use. Note that you can use any name.


Bookmarks

Posting Permissions

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