Jump to content

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

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.