Jump to content

Trouble moving files to directory selected in form.


strago

Recommended Posts

How do you use a form to select where files get moved to after being uploaded, and for zip files, unzipped?? No matter what I try doing, they show up at /full_path/calendar/images/ instead of /full_path/calendar/images/FormInfo.

 

<?php
if($_FILES["zip_file"]["name"]) {
$filename = $_FILES["zip_file"]["name"];
$directory = $_FILES["directory"]["name"]; //Is this even correct??
$source = $_FILES["zip_file"]["tmp_name"];
$type = $_FILES["zip_file"]["type"];

$name = explode(".", $filename);
$accepted_types = array('application/zip', 'application/tiff', 'application/png', 'application/gif', 'application/jpg', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
foreach($accepted_types as $mime_type) {
if($mime_type == $type) {
$okay = true;
break;
}
}

$continue = strtolower($name[1]) == 'zip' ? true : false;
if(!$continue) {
$message = "The file you are trying to upload is not a correct file. Please try again.";
}
$target_path = "/full_path/calendar/images/".$filename; // change this to the correct site path
if(move_uploaded_file($source, $target_path)) {
$zip = new ZipArchive();
$x = $zip->open($target_path);
if ($x === true) {
$zip->extractTo("/full_path/calendar/images/"); // change this to the correct site path
$zip->close();

unlink($target_path);

}
$message = "Your file was uploaded. If it was a Zip file, it has also been unzipped.";
} else {
$message = "There was a problem with the upload. Please try again.";
}
}
?>
<title>File Uploaded</title>
</head>

<body>
<?php if($message) echo "<p>$message</p>"; ?>
<form enctype="multipart/form-data" method="post" action="">
<label>Choose an image file to upload. To upload multiple images at one time, convert them to a .zip file and upload.
<P><input type="file" name="zip_file" /></label>
<P>
Select Directory: <select name="directory" id="directory">
	 <option value="DirectoryName" selected>DirectoryName</option>
<P>
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>

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.