April 1, 200917 yr Hey guys Simple question. I have an image upload form which submits to a directory. All works fine...but I want the script to allow the end user to select which directory they want it submitting to. At the moment it submits to a standard uploads/ folder. So I've added in a dropdown menu with the directory selections. Question: How do I feed this information into the uploader.php script? I've had a go at replacing: $target_path = "uploads/"; for this $target_path = $list +[/]; Any help would be much appreciated and as you can probably guess I'm a beginner at this! Cheers! Upload.php <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <label>list <select name="list" id="list"> <option value="option1">option1</option> <option value="option2">option2</option> </select> </label><br /> Choose a file to upload: <input name="uploadedfile" type="file" /> <input type="submit" value="Upload File" /> </form> Uploader.php <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded. <a href=\"members.php\">Go Back</a>"; } else{ echo "There was an error uploading the file, please try again!"; } ?>
April 1, 200917 yr Hi Josh, change: $target_path = "uploads/"; to $target_path = $_POST['list'] .'/'; so that the form field called 'list' is used for the location. I would personally avoid using names like list as it is a function name as well.
Create an account or sign in to comment