Page 1 of 1

How to unzip a file on a remote server

Posted: Thu Jul 02, 2009 7:38 pm
by tox0tes
I need to be able to call upon a remote .zip file located at an http:// address, unzip it, and store the contents in a directory in my server. How can this be done using PHP?

Re: How to unzip a file on a remote server

Posted: Thu Jul 02, 2009 7:54 pm
by requinix
The easiest way would be to shell (ha) out the work to the system. Meaning, let PHP do the bare minimum necessary.

On Unix-based systems,

Code: Select all

// download
exec("wget http://www.example.com/path/to/file.zip -O file.zip"); // save as "file.zip"
// unzip
exec("unzip file.zip"); // extract to the same directory
exec("unzip file.zip -d file/"); // extract to ./file/

Re: How to unzip a file on a remote server

Posted: Thu Jul 02, 2009 8:02 pm
by emix
1) download a file using any method possible
2) use PHP Zip extension if possible or download any Zip class from the internet to unpack it

Re: How to unzip a file on a remote server

Posted: Thu Jul 02, 2009 8:11 pm
by tox0tes
I think I know how to unzip a local file, but the problem is making the file local. How can I use PHP to retrieve an external file and place it in a directory on my server?

Re: How to unzip a file on a remote server

Posted: Thu Jul 02, 2009 9:33 pm
by jackpf