开发者

PHP upload image and file to a specified folder

开发者 https://www.devze.com 2023-01-20 22:41 出处:网络
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.

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 "s开发者_如何学JAVAelect_value/input_value/random_name_file.txt"

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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消