简体   繁体   English

在多个文件夹中上传多个文件

[英]upload multiple files on multiple folders

I am trying to upload three different files (images) to three different directories, I tried this我正在尝试将三个不同的文件(图像)上传到三个不同的目录,我试过这个

edit编辑
for example file1->directory1, file2->directory2 and file3->directory3例如 file1->directory1、file2->directory2 和 file3->directory3
I am using three different input='file'我正在使用三种不同的 input='file'

$images = $_FILES['image']['name'];
$tmp_dir = $_FILES['image']['tmp_name'];
$imageSize = $_FILES['image']['size'];
$upload_dir = '../img/products/';
$imgExt = strtolower(pathinfo($images,PATHINFO_EXTENSION)); 

$thumbs = $_FILES['thumb']['name'];
$tmp_dir_1 = $_FILES['thumb']['tmp_name'];
$imageSize_1 = $_FILES['thumb']['size'];
$upload_dir_1 = '../img/products/productthumbs';
$imgExt_1 = strtolower(pathinfo($thumbs,PATHINFO_EXTENSION));

$orderthumbs = $_FILES['ordthumb']['name'];
$tmp_dir_2 = $_FILES['ordthumb']['tmp_name'];
$imageSize_2 = $_FILES['ordthumb']['size'];
$upload_dir_2 = '../img/products/orderthumbs';
$imgExt_2 = strtolower(pathinfo($orderthumbs,PATHINFO_EXTENSION));

move_uploaded_file($tmp_dir, $upload_dir.$images);
move_uploaded_file($tmp_dir_1, $upload_dir_1.$thumbs);
move_uploaded_file($tmp_dir_2, $upload_dir_2.$orderthumbs);

but it does not seem to work.但它似乎不起作用。 I can't seem to be able to find the answer somewhere.我似乎无法在某处找到答案。

it was actually really simple but it didn't cross my mind until I browsed the products folder for the images and checked the inspection tool of chrome, I saw that all the images uploaded in the products file and were renamed as orderthumbs+file_name and productthumbs+file_name.其实很简单,但是直到我浏览了图片的产品文件夹并检查了chrome的检查工具,我才发现所有图片上传到产品文件中并重命名为orderthumbs+file_name和productthumbs +文件名。

The issue was this part $upload_dir_2 = '../img/products/orderthumbs';问题是这部分$upload_dir_2 = '../img/products/orderthumbs'; when it should be $upload_dir_2 = '../img/products/orderthumbs/';什么时候应该是$upload_dir_2 = '../img/products/orderthumbs/'; the last slash that was missing renamed the files and send them to the /img/products directory.丢失的最后一个斜杠重命名了文件并将它们发送到 /img/products 目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM