PHP Force uploads corrupted file

Hi, I am currently working on some php-zend framework project on my osx-apache. The problem is when ever I want to force a download of some files using my php app, the uploaded files will get corrupted and the file size is 5.4 kb! I tried so many changes in my code and even used some classes to force loading, but the problem remains the same! I have to say that I have used force loading in the actions of my controllers. Does overwriting something or something like that affect file upload ?!

This is the basic code:

header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file["files_url"]));
    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["files_url"]));
    ob_clean();
    flush();
    readfile($file["files_url"]);
    exit;*/

      

And the classes I use are: BF_Download

$download = new Download($file["files_url"],$file["files_title"],"on",20);
    $download->download_file();

      

AND:

$zip = new zip_file("../".$file["files_title"].".zip");

    $zip->set_options(array('inmemory' => 1, 'recurse' => 0, 'storepaths' => 0));
    $zip->add_files($file["files_url"]);
    $zip->create_archive();
    $zip->download_file();*/

      

+2


source to share


3 answers


Ok, I found the problem using the last comment from dcaunt . Actually I just look at the binary source of the output file and noticed that there is a small character and a space on a newline on the first line, so by removing them the file reverts to normal and becomes readable. So to strip out those spaces, I decided to remove the end of my php script tag "?>" In my controller, and this makes php not post them to the output content. Any thanks to everyone for your comments :)



+2


source


Try viewing the file as binary data on a webpage. What can happen is that some PHP error lurks in the output and mangles it.

So, skip the content type headers and just look at the raw data.



If you still can't see it, keep it in tact and look at your error log.

+4


source


I highly recommend using this Action Helper to send files - it can send data from memory or file to disk and makes it easy to set caching and content options

Despite the name SendFile, apache sendfile is optional.

0


source







All Articles