strago Posted January 30, 2013 Share Posted January 30, 2013 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> Quote Link to comment Share on other sites More sharing options...
Zane Posted January 30, 2013 Share Posted January 30, 2013 (edited) directory does not come from a file-input field. It should be $_POST['directory'] Edited January 30, 2013 by Zane Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.