note 52658 added to ref.zip
| From: | epete05 at gmail dot com | Date: | Mon, 09 May 2005 01:03:33 +0000 |
| Subject: | note 52658 added to ref.zip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89134@lists.php.net to get a copy of this message | ||
I am having difficulties opening jpeg images from a zip file and then writing them to the disk. All
the images get extracted... the filesizes look about the same but when i try to open them i get a
'cannot open file' error. Does anyone have a clue as to what is going on? Here is the
function I am using:
<?php
function Unzip($dir, $file, $destiny)
{
$dir .= '\\';
$path_file = $dir . $file;
$unzipdr = $dir.$destiny;
if ( is_dir($pathname) || empty($pathname) )
{
echo 'Directory Exists... moving on<br>';
}
else
{
mkdir($destiny);
}
$zip = zip_open($path_file);
$_tmp = array();
$count=0;
echo $unzipdr.'<br>';
if ($zip)
{
while ($zip_entry = zip_read($zip))
{
echo zip_entry_name($zip_entry).'<br>';
$_tmp[$count]["filename"] = zip_entry_name($zip_entry);
$_tmp[$count]["stored_filename"] = zip_entry_name($zip_entry);
$_tmp[$count]["size"] = zip_entry_filesize($zip_entry);
$_tmp[$count]["compressed_size"] = zip_entry_compressedsize($zip_entry);
$_tmp[$count]["mtime"] = "";
$_tmp[$count]["comment"] = "";
$_tmp[$count]["folder"] = dirname(zip_entry_name($zip_entry));
$_tmp[$count]["index"] = $count;
$_tmp[$count]["status"] = "ok";
$_tmp[$count]["method"] = zip_entry_compressionmethod($zip_entry);
if (zip_entry_open($zip, $zip_entry, "r"))
{
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
/*
if($destiny)
{
$path_file = str_replace("/",DIRECTORY_SEPARATOR, $destiny .
zip_entry_name($zip_entry));
}
else
{
$path_file = str_replace("/",DIRECTORY_SEPARATOR, $dir .
zip_entry_name($zip_entry));
}
$new_dir = dirname($path_file);
// Create Recursive Directory
mkdir($new_dir);
*/
chdir($unzipdr);
$fp = fopen(zip_entry_name($zip_entry), "wb");
fwrite($fp, $buf);
fclose($fp);
zip_entry_close($zip_entry);
}
$count++;
}
zip_close($zip);
}
else { echo 'aww crap'; }
chdir($dir);
}
$file = 'Funeral.zip';
$dir = getcwd();
$album = 'Funeral 04';
echo $dir;
Unzip($dir, $file, $album);
?>
This is only slightly modified from a recent addition here.
----
Manual Page -- http://www.php.net/manual/en/ref.zip.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52658
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52658&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52658&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52658&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52658&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52658&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52658&report=yes
Search -- http://master.php.net/manage/user-notes.php