开发者

'no files to extract' message, when trying to extract zip which was downloaded forcefully

When i try to extract the zip folder that i downloaded from the server forcefully, i get the message, 'no files to extract'. But when i download the zip folder directly from the server, i am able to extract it properly. Here is the code that i used开发者_Python百科 to download forcefully.

$file = 'absolute/path/to/the/zip/folder';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@readfile($file); 

Does anyone know why this is happening? Any help would be appreciated. Thanks in advance


I cannot answer the question, but here are a few ideas to try out:

  • Try a different mimetype, such as the generic application/octet-stream.
  • Attach Fiddler (or any other HTTP debugger) and look at the transfer. What do you see? Is the file being downloaded? Maybe there is an invalid Content-Length header for some reason?
  • As noted by @middaparka in comments, don't suppress errors from readfile().


It's tricky to tell if it's due to the headers you're using or a server issue. However, I generally use the following without any problems:

header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=".basename($file));

readfile($file);
exit();

As such, you might want to try the above and see if that makes any difference. (At a guess, if your connection is slow the fact that you're not supplying a Content-Length header might not be helping the situation.)


Thank you everybody for your support. I found the solution. I had used mkdir function before headers were sent. It seems this was generating some error, so error was outputted before the headers and thereby causing the problem. When i suppressed the errors using '@' operator, the problem got solved. :). Earlier, i got the following message from fiddler: "Fiddler has detected a protocol violation in session #4. The Server did not return properly formatted HTTP Headers. Maybe missing altogether (e.g. HTTP/0.9), maybe only \r\r instead of \r\n\r\n?"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜