How to unzip a file on a remote server

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
tox0tes
Forum Newbie
Posts: 4
Joined: Sun Jun 28, 2009 4:54 pm

How to unzip a file on a remote server

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to unzip a file on a remote server

Post 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/
User avatar
emix
Forum Newbie
Posts: 8
Joined: Mon Jun 22, 2009 10:32 am
Location: Poland

Re: How to unzip a file on a remote server

Post 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
tox0tes
Forum Newbie
Posts: 4
Joined: Sun Jun 28, 2009 4:54 pm

Re: How to unzip a file on a remote server

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to unzip a file on a remote server

Post by jackpf »

Post Reply