Jump to content

extract zip and link the file


IrOnMaSk

Recommended Posts

Hi guys,

I'm using this upload/extract zip script. I wonder if I can modify the script to link the file after it is unzip. Now it just unzip and show the content, I want to give the link to that content. Please let me know if this even possible with the code below.

<form enctype="multipart/form-data" action="index.php" method="POST">
Upload a Zip Archive (*.zip): <input name="zip" type="file" /><input type="submit" value="Upload" />
</form>
<?php
/*
UnZip on Server - using PHP
by 3scriptz.com  
*/  
//check if file is uploaded
if(isset($_FILES['zip'])){
require_once('pclzip.lib.php'); //include class

$upload_dir = 'uploads'; //your upload directory NOTE: CHMODD 0777
$filename = $_FILES['zip']['name']; //the filename

//move file
if(move_uploaded_file($_FILES['zip']['tmp_name'], $upload_dir.'/'.$filename))
    echo "Uploaded ". $filename . " - ". $_FILES['zip']['size'] . " bytes<br />";
else
	die("<font color='red'>Error : Unable to upload file</font><br />");

$zip_dir = basename($filename, ".zip"); //get filename without extension fpr directory creation

//create directory in $upload_dir and chmodd directory
if(!@mkdir($upload_dir.'/'.$zip_dir, 0777))
	die("<font color='red'>Error : Unable to create directory</font><br />");

$archive = new PclZip($upload_dir.'/'.$filename);

if ($archive->extract(PCLZIP_OPT_PATH, $upload_dir.'/'.$zip_dir) == 0)
	die("<font color='red'>Error : Unable to unzip archive</font>");

//show what was just extracted
$list = $archive->listContent();
echo "<br /><b>Files in Archive</b><br />";
for ($i=0; $i<sizeof($list); $i++) {

	if(!$list[$i]['folder'])
		$bytes = " - ".$list[$i]['size']." bytes";
	else
		$bytes = "";

	echo "".$list[$i]['filename']."$bytes<br />";
}

unlink($upload_dir.'/'.$filename); //delete uploaded file
}
?>

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.