Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Error handling force download.. :(

    I need to provide download for php file on my site.

    I use this script:
    PHP Code:
    session_cache_limiter('none'); //*Use before session_start()
    session_start();

    $file 'file.php';
    _Download("hiddendir/".$file$file);

    function 
    _Download($f_location,$f_name){
        
    header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        
    header('Content-Description: File Transfer');
        
    header('Content-Type: application/octet-stream');
        
    header('Content-Length: ' filesize($f_location));
        
    header('Content-Disposition: attachment; filename=' basename($f_name));
        
    readfile($f_location);
     } 
    but give me this error: Warning: Cannot modify header information - headers already sent by (output started at ....

    then I use force download scripts from http://www.zubrag.com/scripts/ and http://www.gowondesigns.com/?page.getfile

    they works well, then i added 'php' => 'application/octet-stream' to the configuration of both script. but it doesn't work.

    could somebody help me pls...

    thank you.

  • #2
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    the headers already sent error is because you cant run the header() command after any text of anything has been sent. Maybe a white space at the beginning of the file? or the end of a configuration file?


    -Adam
    Why not thank me?

    http://adamsworld.name

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    The portion of the error message that you did not post states where the output was started that is preventing the headers from being sent.

    Read the error message or post the whole error if you want specific help with the problem.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oh, i got it, the problem is because i inserted that code after another code.
    is header session only works in one single php file and cannot inserted into another file?

    how to solve the problem, because i need this script between my another code.

    thank you.

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    You can put that code anywhere you want, as long as no output has been sent yet.

    Output is anything echoed, printed or any characters outside of PHP blocks.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    You cannot insert the actual download code in web page. It must be in its own .php file and there must be a link to that file placed on a web page. You click the link to request the page that causes the file to be downloaded.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oh I see now.
    thank you for the enlightment and forgive me for my lackness.


  •  

    Posting Permissions

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