Jump to content

Upload and Extract - Question


Canman2005

Recommended Posts

Hi all

 

Wondering if you can help me.

 

Basically, I have a script which allows you to upload a zip file, the script then creates a folder and the zip file is then dumped on the server into that folder location, the scrip then takes the uploaded zip file and extracts the files.

 

The code im using is

 

<?php
if ($_POST['action'] == 'add')
{
$rand = rand(100,999);

mkdir('zipfiles/'.$rand.'');
$upload_folder = 'zipfiles/'.$rand.'/';
$upload_factsheets = str_replace("'", "", $upload_folder.$rand.$_FILES['fs']['name']);
if (move_uploaded_file($_FILES['fs']['tmp_name'], $upload_factsheets))
{
system('unzip "'.$upload_factsheets.'"');
print $upload_factsheets;
}
else
{
print "<script>alert ('There was a problem with your file');</script>";
}
}

?>
<form method="post" enctype="multipart/form-data">
<input name="fs" type="file" class="style11normblack" id="fs" />
<input name="Submit" type="submit" class="style11normblack" value="Add" />
<input name="action" type="hidden" id="action" value="add" />
</form>

 

The problem is that the above script dumps the zip files into the same folder as the php page is in, I cant seem to set a target folder for the unzipped files.

 

Does anyone know how I can target the zip file to unzip the files into the same folder as the zip file is uploaded.

 

Does that make sense?

 

Thanks in advance

 

Ed

Link to comment
https://forums.phpfreaks.com/topic/63759-upload-and-extract-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.