开发者

Error when unzipping a group of images

I am importing public domain books from archive.org to my site, and have a php import script set up to do it. However, when I attempt to import the images and run

exec( "unzip $images_file_arg -d $book_dir_arg", $output, $status );

it will occasionally return me a $status of 1. Is this ok? I hav开发者_如何学Ce not had any problems with the imported images so far. I looked up the man page for unzip, but it didn't tell me much. Could this possibly cause problems, and do I have to check each picture individually, or am I safe?


EDIT: Oops. I should have checked the manpage straight away. They tell us what the error codes mean:

The exit status (or error level) approximates the exit codes defined by PKWARE and takes on the following values, except under VMS:

  1. normal; no errors or warnings detected.

  2. one or more warning errors were encountered, but processing completed successfully anyway. This includes zipfiles where one or more files was skipped due to unsupported compression method or encryption with an unknown password.

  3. a generic error in the zipfile format was detected. Processing may have completed successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.

  4. a severe error in the zipfile format was detected. Processing probably failed immediately.

(many more)

So, apparently some archives may have had files in them skipped, but zip didn't break down; it just did all it could.


It really should work, but there are complications with certain filenames. Are any of them potentially tricky with unusual characters? escapeshellarg is certainly something to look into. If you get a bad return status, you should be concerned because that means zip exited with some error or other. At the very least, I would suggest you log the filenames in those case (error_log($filename)) and see if there is anything that might cause problems. zip itself runs totally independantly of PHP and will do everything fine if it's getting passed the right arguments by the shell, and the files really are downloaded and ready to unzip.


Maybe you are better suited with the php integrated ziparchive-class. http://www.php.net/manual/de/class.ziparchive.php

Especially http://www.php.net/manual/de/function.ziparchive-extractto.php it returns you TRUE, if extracting was successful, otherwise FALSE.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜