Jump to content

readfile in php isn't downloading file


treeleaf20

Recommended Posts

All,

I've got the following code to force a file download for a zipfile that I just created:

    $zip_name = 'download.zip';
    $result = create_zip($other_files_to_zip,$zip_name,true);
    if($result){
    echo "The filesize is: ".filesize($zip_name);
    header('Content-Type: application/zip');
    header('Content-disposition: attachment; filename=filename.zip');
    header('Content-Length: ' . filesize($zip_name));
    readfile($zip_name);
    }

When I echo out the filesize it shows a correct size and it prompts me to download the filename.zip which is ok since it's just a filename but then when I save the document and try and open Windows says that Windows cannot open the folder because the folder is invalid.

 

Any ideas on how to resolve an issue like this?

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/265493-readfile-in-php-isnt-downloading-file/
Share on other sites

Archived

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

×
×
  • Create New...

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.