Log in

View Full Version : need to extract tar.gz online.



chetanmadaan
06-28-2010, 06:14 PM
well, i get files ftped to my server directly from cj.com and i need to extract those online itself... can someone forward me to a script of something which can be hosted on my server and do the job.

right now... i don't have anything which can perform anything like this.

Thanks.

djr33
06-28-2010, 08:30 PM
In PHP, you can use exec() to run linux commands. If you are on a linux server, I believe there are default system commands to extract those files.

chetanmadaan
06-28-2010, 08:39 PM
well... to be honest i am not a server tech or may be a php programmer.

but.

here is the code of the file i have been using to extract zips online for a while.


<?php
$file = $_GET['file'];
$removeorig = $_GET['removeorig'];
$unzipper = $_GET['unzipper'];
if (isset($file))
{
echo "Unzipping " . $file . "...<br />\n";
system('unzip -o ' . $file);
echo "<hr />\n";
if (isset($removeorig)) {
echo "Deleting Zip...<br />\n";
unlink("$file");
}
}
if (isset($unzipper)) {
echo "Deleting Script...<br />\n";
unlink(__FILE__);
echo "Script Deleted!<br /><a href=\"/\">HOME</a>\n";
exit;
}
$handler = opendir(".");
echo "Please choose a file to unzip: <br />\n";
echo '<form action="" method="get">'."\n";
$found = 0;
while ($file = readdir($handler))
{
if(strrchr($file,".zip") != ".zip" ) { continue; }
{
echo '<input type="radio" name="file" value="' . $file . '"/> ' . $file . "<br />\n";
$found = 1;
}
}
echo '<hr/><input type="checkbox" name="removeorig" value="Remove" />Delete .zip after extraction?'."<br />\n";
echo '<input type="checkbox" name="unzipper" value="Remove" checked="checked" />Delete Unzipper Script? (Uncheck this box if you have more files to unzip!)'."<br />\n";
closedir($handler);
if ($found == FALSE)
echo "No .zips found<br />";
else
echo '<br />NOTE: This unzips and <strong>REPLACES</strong> files.<br /><br /><input type="submit" value="Unzip!" />';

echo "\n</form>";
?>

may be we can modify this one :)???

djr33
06-28-2010, 08:42 PM
About 7 lines down, you get the line with system(). Using that you can switch the linux commands to do a .tar.gz. But I don't know what those commands are. Google will know, though.

chetanmadaan
06-28-2010, 08:47 PM
well, the above one shows a list if zips in the directory and has ability to delete the zip and the script itself as well using a checkbox.

now, here is another one.

this one extracts the automatically finds the .tar.gz files and then extracts them and then deletes the files and the script itself as well.

may be we can combine them both into a piece.

Thanks. i am just saying.


<?php
// import the PEAR Archive_Tar class (see http://pear.php.net/package/Archive_Tar)
include ('Archive/Tar.php');

$file = $_SERVER["SCRIPT_NAME"];
$break = preg_split('/\//', $file, -1);
$pfile = $break[count($break) - 1];
echo "<p>You have run $pfile to extract a Joomla tar.gz archive file.</p>";

if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$extn = substr($file, -7);
$source = substr($file, 6);

if ($extn == ".tar.gz" && $source="Joomla")
{
echo "<p>$file file has been found and will be extracted.<p>";
$file_to_extract = $file; // Name of Joomla tar.gz archive file to extract

$obj = new Archive_Tar( $file_to_extract ); // Create archive object to extract

closedir($handle); // A Joomla tar.gz archive file has been found, close directory handler

if ($obj->extract(''))
{
unlink( $file_to_extract ); // Remove source code file
unlink( $pfile ); // Removes this script file to prevent misuse
echo "<p>The source file ($file_to_extract) and the unpack script ($pfile) have been removed.</p>";
exit ("$file_to_extract extracted successfully!");
} else {
echo "<p>WARNING: The source file ($file_to_extract) and the unpack script ($pfile) have NOT been removed.</p>";
exit ('Error in file extraction');
}
}
}
}

closedir($handle);
echo "<p>The unpack script ($pfile) has been removed.</p>";
die('No Joomla source file to extract!');
}
?>

chetanmadaan
06-29-2010, 11:49 PM
bump!