Sunday, January 31, 2010

unzip a file through php directly on the webserver

I recently faced a problem with files transfers to my webserver:
if you have a lot of tiny files (let's say some 5000s) to transfer, it take a long long time so why not compress em all in a bigger file and unzip on the webserver ?
Unfortunately I'm using Aruba where it's not allowed to use the system command so I used exec:

<title>Unzip Page</title>
  $zip= $_GET['filename'];
if($zip === NULL){
echo "Missing filename<br>";
echo "usage: http://url/untar.php?filename=FILENAME.ZIP";
   exec ("unzip $zip");
   echo "file unzipped:$zip<br>";  
   echo "this is provided by <a href=\"\">Lxphotostudio";  

Actually I have to say that you could face some timeouts due to the setting of the webserver, try to tune the size of the files accordingly.

1 comment:

  1. I recently made a small and ugly (absolutely not elegant) script to make my joomla local files syncronize properly with the online aruba webserver:

    if [ $# -lt 1 ]
    echo "usage "
    cp -r $1 /tmp
    chown -R 18825551:100 /tmp/$1
    tar cfvzps file1.tgz -C /tmp/$1 administrator \components language logs robots.txt \installation_done includes

    tar cfvzps file2.tgz -C /tmp/$1 images
    tar cfvzps file3.tgz -C /tmp/$1 \configuration.php CREDITS.php includes \INSTALL.php LICENSES.php plugins xmlrpc \demo.flv index2.php libraries CHANGELOG.php \configuration.php-dist htaccess.txt index.php \media templates COPYRIGHT.php modules tmp

    rm -fr /tmp/$1
    echo "done:"
    ls -l file*.tgz

    I just put it here to avoid losing it

    NB the strange groupid and userid is due to my aruba webserver ids and are necessary to keep permissions even if I noticed that you have to change the php file permissions by hand to 744 (local apache 2 uses 644 and is happy with that) to make it work.