Page 1 of 1
Zip Files
Posted: Mon Jan 19, 2009 9:39 pm
by cavaliernavyman
Hello fellow code monkeys. I have a problem which I have beat my head against a wall

trying to solve. I want to unzip the contents of a zip file AND save/extract/view the ORIGINAL date modified. But when I use extractTo($zip_file_name), the date modified is reset. Does anyone know of a way to check the date modified of each file before unzipping it, or perhaps another solution?
Thanks in advance!

Re: Zip Files
Posted: Mon Jan 19, 2009 10:52 pm
by it2051229
Re: Zip Files
Posted: Mon Jan 19, 2009 11:13 pm
by cavaliernavyman
it2051229, thanks for the post; however, I couldn't find the solution there. It is a well written guide for working with files in PHP though...
Re: Zip Files
Posted: Mon Jan 19, 2009 11:22 pm
by jack_indigo
cavaliernavyman wrote:it2051229, thanks for the post; however, I couldn't find the solution there. It is a well written guide for working with files in PHP though...
Huh? You already have $zip_file_name, right? Or do you need us to show you how to use dir() to iterate a directory of files? Anyway, then if you look in that link that it2051229 had posted, you'd see this gem:
Code: Select all
<?php
$results = stat ("/tmp/php_essentials.txt");
echo "File size is $results[size]" . "<br>";
echo "File last modifed on $results[mtime]" . "<br>";
echo "File occupies $results[blocks] filesystem blocks" . "<br>";
?>
Line 3 is the value you want. So, if you know the name of the file, such as your var $zip_file_name, then apply stat() on it (as long as it has the directory path in the filename already there), get the array back, and then do $results[mtime] on it to get the value you wanted. If that returns a numeric value, then they might be giving you the value in Unix time, so you have to convert from Unix time to a time format like Y-m-d H:i:s or m-d-Y H:i:s. Now, if you don't know the file name because it's a set of files in a directory, then you need to simply google on how to use php and dir() to iterate a directory of files to find the file name you want and then run the stat() function on it.
Re: Zip Files
Posted: Mon Jan 19, 2009 11:54 pm
by cavaliernavyman
OK, to clarify. I understand how to unzip files, and I know how to get all kinds of information about the new file, including its date modified. BUT, in the process of unzipping the file, the date modified is RESET. Thus, if I created the file on March 16th and zipped it, you'll see that inside the zip, the file has March 16th as the date last modified. But, if you use PHP to unzip the file, the new file will have, in this case, Jan 20th as its date last modified. What I want to know is how to preserve the date last modified, or at least access it before unzipping...
Thanks for all the help folks
Re: Zip Files
Posted: Tue Jan 20, 2009 1:15 am
by jack_indigo
Good luck on that one. To be honest I think you'll be looking at writing something in C or C++ and linking it in as a PHP module (or do a cheesy shell out to command line with backtick characters) to do what you're asking.