simone
simone

Reputation: 811

PHP upload image and file to a specified folder

Hi all i need to create a form to upload two files to a specified folder that is created by the selection of a select and an input on the same page.

So the form must have:
input type="text"
select
upload image on the folder "select_value/input_value/random_name_image.jpg"
upload file on the folder "select_value/input_value/random_name_file.txt"

someone can help me to create this form? thanks a lot

Upvotes: 0

Views: 2391

Answers (1)

Rebecca Scott
Rebecca Scott

Reputation: 2431

Something like this:

// Build destination path from the text input and select
$dest = ...;

if (!move_uploaded_file($_FILES['image']['tmp_name'], "{$dest}/{$_FILES['image']['name']}")) {
  echo('Error with image');
  die();
}
if (!move_uploaded_file($_FILES['file']['tmp_name'], "{$dest}/{$_FILES['file']['name']}")) {
  echo('Error with image');
  die();
}

Check out move_uploaded_file() for more information. Make sure your form has enctype="multipart/form-data" specified (major waste of time if you forget that).

Upvotes: 1

Related Questions