Results 1 to 6 of 6

Thread: need to extract tar.gz online.

  1. #1
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default need to extract tar.gz online.

    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.
    Last edited by chetanmadaan; 06-28-2010 at 06:38 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    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.

    Code:
    		<?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 ???

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    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.

    Code:
    <?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!');
    	}
    ?>

  6. #6
    Join Date
    Apr 2008
    Location
    Little Office!
    Posts
    80
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    bump!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •