I have just about had it with web servers that give no shell access and operate in safe mode. I wanted to install Dataface on my webspace here at sjhannah.com. The full installation is about 2.6 megs as a compressed tar file (much much bigger uncompressed) so it is kind of unfeasible to upload the uncompressed files to the server. Given the tendency of ftp to hang before during and after each file is uploaded, it would likely take 5 to 6 hours to upload the conventional way using an FTP client.

What I really needed to be able to do was upload the compressed tar archive to the server, then extract its contents on the server. Sounds easy, right. Well not when your server doesn’t provide shell access and PHP is executed in safe mode. Okay, Okay, normally you could create a PHP script like the following:

`

< ?
system("tar -xvfz filename.tar.gz");

?>

`

Except for the fact that my server doesn’t even provide ‘tar’ in the path – so even this command won’t work on my server.

PEAR to the rescue!!!

PEAR is a repository for reusable PHP classses. When I need to get something done in PHP, PEAR is usually the first place where I look. Luckily I found a great class called Achive_Tar that provides a pure PHP solution for Tar file manipulation.

After downloading and installing the class in my web space I wrote a new script to take care of the extraction:

`

< ?
require_once 'Archive/Tar.php';
$archive = new Archive_Tar($_GET['filename']);

$res = $archive->extract();
if ( PEAR::isError($res) ){
	echo $res->toString();
}

?>

`

This script takes a get parameter ‘filename’ to specify the name of the file to be extracted. It then extracts that file into the same directory!! And voila!! we can run this script and extract our file.