PHP Multiple File Uploading

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

I think it's easier to simply make a proper array first.

$n =
$files = [];
for ($i = 0; $n > $i; $i++) {
$files[$i]['name'] = $_FILES['files']['name'][$i];
$files[$i]['type'] = $_FILES['files']['type'][$i];
$files[$i]['tmp_name'] =
$files[$i]['error'] =
$files[$i]['size'] = $_FILES['files']['size'][$i];
}

For two files gives you an array:

$files = [
0 => [
'name' => 'image01.jpg',
'type' => 'image/jpeg',
'tmp_name' => 'tmp01.tmp',
'error' => 0,
'size' => 2048
],
1 => [
'name' => 'image02.jpg',
'type' => 'image/jpeg',
'tmp_name' => 'tmp02.tmp',
'error' => 0,
'size' => 1024
]
];

Which is much easier to deal with then. Then you can use the exact same logic as for one file...but in an "foreach" loop.

Usually Alex and the gang are very good at simplifying the task but this seemed to be unnecessarily complex.

LukeWatts
Автор

Brilliant - thanks. Only thing that would have made it totally perfect is to know how to return a success or fail message that doesn't have words like 'array' which nobody really understands

arendzen
Автор

Nicet tutorial - and I love the idea of using pure PHP, instead of some framework. However, I think the structure with all those nested IFs is a bit of a shame. In any event, thanks for that. It was good.

davidconnelly
Автор

Nice tutorial. Which macbook do you use, anyway? Please tell me the specs I am also considering on buying a macbook.

chauhanssaksham
Автор

Hi, Thanks for the video. However, I am trying to upload some files using the same logic but I couldnt do so. I placed echo statements at different places to debug my code and figured out that the control is not entering 'foreach' loop. Could you please help?

aggarwalkashish
Автор

You could create function that converts $_FILES to normal type of array

ArnoldsKtm
Автор

Do you have a tutorial about downloading the uploaded file??

genji
Автор

on some files larger than 2mb not show me any error or message. 
the weird part is that the files are not uploaded.
simply do nothing.
I am very confused

alexberea
Автор

I used this code to upload Images to my website, but for some reason this code doesn't let me upload more than 20 Images. If i try to upload 35 Images, 15 will be dropped.

bertenbevers
Автор

hey i want to insert data from each file additional to this. But I am unable to do this. Please help me doing this.

jinalkothari
Автор

mcm mana nak set file tu, dlm bhsa melayu pun xfhm steps nya

dedeque
Автор

how do I trigger the upload without clicking the upload button??

blindbandit
Автор

it says completed but no files in the directory.. how to fix that??

blindbandit
Автор

Parse error: syntax error, unexpected ';' in on line 35
plz help

martijnschuman
Автор

How can I do this for phpmyadmin (mySQL)? Pls help

mihaelaandreea
Автор

this code is wrong, it is not working

himankpandya
Автор

upload with 2 or more image upload control with one submit button in to one table only
how to do that

Dkm
Автор

This is a confusing example too much jumping backwards and forward that it almost seems to be intentionally showing off and confusion intended. Sorry but this good coding sucks because it is not straight forward knowledge.

grantdavis