Zip Files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cavaliernavyman
Forum Newbie
Posts: 3
Joined: Mon Jan 19, 2009 9:34 pm

Zip Files

Post by cavaliernavyman »

Hello fellow code monkeys. I have a problem which I have beat my head against a wall :banghead: 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! :drunk:
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Zip Files

Post by it2051229 »

cavaliernavyman
Forum Newbie
Posts: 3
Joined: Mon Jan 19, 2009 9:34 pm

Re: Zip Files

Post 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...
jack_indigo
Forum Contributor
Posts: 186
Joined: Sun Jun 08, 2008 11:25 pm

Re: Zip Files

Post 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.
cavaliernavyman
Forum Newbie
Posts: 3
Joined: Mon Jan 19, 2009 9:34 pm

Re: Zip Files

Post 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
jack_indigo
Forum Contributor
Posts: 186
Joined: Sun Jun 08, 2008 11:25 pm

Re: Zip Files

Post 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.
Post Reply