note 56003 modified in ref.zip by danbrown

From: Date: Sun, 25 Oct 2009 13:13:02 +0000
Subject: note 56003 modified in ref.zip by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162062@lists.php.net to get a copy of this message
i try to find function that will show exists file in zip archive or not. of course i not found it. and so write mine: first will just check archive for list of files, if not found all files function return FALSE: <?php function zipx_entries_exists() { $names=array(); $args=func_get_args(); $far_size=count($args); if($args[0]) { for(; $zip_entry=zip_read($args[0]); $names[]= zip_entry_name($zip_entry)); for($x=1; $x<=$far_size; $t+=in_array($args[$x], $names), $x++); return $t==--$far_size; }else{ return 'No zip file in descriptor!'; } } example: $zip=zip_open('any_zip_file_zip'); var_dump(zip_entries_exists($zip, 'photo_1.jpg', 'photo_2.jpg')); second function will try to find files in zip, if not found it return string with names of not found files with specified delimeter: function zipx_entries_nonexists_list() { $names=array(); $args=func_get_args(); $m=NULL; $far_size=count($args); if($args[0]) { for(; $zip_entry=zip_read($args[0]); $names[]= zip_entry_name($zip_entry)); for($x=2; $x<=$far_size; $m.=(in_array($args[$x], $names) ? NULL : $args[$x].$args[1]), $x++); return trim($m, $args[1]); }else{ return 'No zip file in descriptor!'; } } ?> example: <?php $zip=zip_open('any_zip_file_zip'); var_dump(zip_entries_nonexists_list($zip, '<br />', 'photo_1.jpg', 'photo_2.jpg')); ?> it will return if not found files: photo_1.jpg<br />photo_2.jpg --was-- i try to find function that will show exists file in zip archive or not. of course i not found it. and so write mine: first will just check archive for list of files, if not found all files function return FALSE: function zipx_entries_exists() { $names=array(); $args=func_get_args(); $far_size=count($args); if($args[0]) { for(; $zip_entry=zip_read($args[0]); $names[]= zip_entry_name($zip_entry)); for($x=1; $x<=$far_size; $t+=in_array($args[$x], $names), $x++); return $t==--$far_size; }else{ return 'No zip file in descriptor!'; } } example: $zip=zip_open('any_zip_file_zip'); var_dump(zip_entries_exists($zip, 'photo_1.jpg', 'photo_2.jpg')); second function will try to find files in zip, if not found it return string with names of not found files with specified delimeter: function zipx_entries_nonexists_list() { $names=array(); $args=func_get_args(); $m=NULL; $far_size=count($args); if($args[0]) { for(; $zip_entry=zip_read($args[0]); $names[]= zip_entry_name($zip_entry)); for($x=2; $x<=$far_size; $m.=(in_array($args[$x], $names) ? NULL : $args[$x].$args[1]), $x++); return trim($m, $args[1]); }else{ return 'No zip file in descriptor!'; } } example: $zip=zip_open('any_zip_file_zip'); var_dump(zip_entries_nonexists_list($zip, '<br />', 'photo_1.jpg', 'photo_2.jpg')); it will return if not found files: photo_1.jpg<br />photo_2.jpg http://php.net/manual/en/ref.zip.php

« previous php.notes (#162062) next »