[PHP] Autorename extracted files from zip-archive

2011-01-19 Thread Merlin Morgenstern

Hello,

I am using shell_exec to uncompress zip files which works fine, but has 
one big problem. Whenever the zip-archive containes an already existing 
file name, it will overwrite the current one. I need the file to be 
extracted and autorenamed.


This is the code line:

$output = shell_exec('unzip -jo '.$filename.' -d '.$path);

Does anybody know a way on how to autorename existing files?

I thought about a workaround on extracting to a tmp folder and then 
moving to the proper directory while renaming the files if they already 
exists. Unfortunatelly I could not find a way to do this.


Thank you for any help on this.

Merlin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Autorename extracted files from zip-archive

2011-01-19 Thread Daniel Brown
On Wed, Jan 19, 2011 at 09:06, Merlin Morgenstern merli...@fastmail.fm wrote:
 Hello,

 I am using shell_exec to uncompress zip files which works fine, but has one
 big problem. Whenever the zip-archive containes an already existing file
 name, it will overwrite the current one. I need the file to be extracted and
 autorenamed.

 This is the code line:

        $output = shell_exec('unzip -jo '.$filename.' -d '.$path);

 Does anybody know a way on how to autorename existing files?

Just because you're using PHP as a frontend doesn't mean this is a
PHP question.  This is a Linux administration question, and one that
Google can handle.

 I thought about a workaround on extracting to a tmp folder and then moving
 to the proper directory while renaming the files if they already exists.
 Unfortunatelly I could not find a way to do this.

Probably because you haven't written it yet.  When you think about
how to achieve this, it's really simple:

1.) Create a temporary directory (e.g. -
mkdir(dirname(__FILE__).'/tmp'.time()) for a unique name).
2.) Extract the files to that directory.
3.) Check the target directory for existing files.
4.) Handle things as appropriate.

There are even simpler ways, again available by searching Google,
you may just need to adjust your search terms and try again.

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Autorename extracted files from zip-archive

2011-01-19 Thread Tommy Pham
 -Original Message-
 From: Merlin Morgenstern [mailto:merli...@fastmail.fm]
 Sent: Wednesday, January 19, 2011 6:06 AM
 To: php-general@lists.php.net
 Subject: [PHP] Autorename extracted files from zip-archive
 
 Hello,
 
 I am using shell_exec to uncompress zip files which works fine, but has
one
 big problem. Whenever the zip-archive containes an already existing file
 name, it will overwrite the current one. I need the file to be extracted
and
 autorenamed.
 
 This is the code line:
 
   $output = shell_exec('unzip -jo '.$filename.' -d '.$path);
 
 Does anybody know a way on how to autorename existing files?
 
 I thought about a workaround on extracting to a tmp folder and then moving
 to the proper directory while renaming the files if they already exists.
 Unfortunatelly I could not find a way to do this.
 
 Thank you for any help on this.
 
 Merlin
 

Merlin,

It's a shame that unzip doesn't have that feature like unrar.  However, I
suggest you extract the contents of the zip files into a temp working
directory.  Scan the files within that directory for any compressed archives
and extract each into their own subdirectory matching the filename.  And
just recurse until no more compressed archives.  Then process whatever files
you need.  When done, just rm -fd tmpworkdir  (my unix/linux is limited.
Don't recall the parameters).  That way, clean up is a synch and you still
have the original file when there's something wrong during processing stages
like mismatch columns, duplicate entries, etc.

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Autorename extracted files from zip-archive

2011-01-19 Thread Richard Quadling
On 19 January 2011 14:06, Merlin Morgenstern merli...@fastmail.fm wrote:
 Hello,

 I am using shell_exec to uncompress zip files which works fine, but has one
 big problem. Whenever the zip-archive containes an already existing file
 name, it will overwrite the current one. I need the file to be extracted and
 autorenamed.

 This is the code line:

        $output = shell_exec('unzip -jo '.$filename.' -d '.$path);

 Does anybody know a way on how to autorename existing files?

 I thought about a workaround on extracting to a tmp folder and then moving
 to the proper directory while renaming the files if they already exists.
 Unfortunatelly I could not find a way to do this.

 Thank you for any help on this.

 Merlin

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



As you are using an external app (unzip), does it support any sort of
renaming? PHP isn't actually involved in the extraction process in
this instance.

You may be better off using the ZIP extension in PHP to extract the
data and write it to your own files.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php