How do you loop through $_FILES array?

前端 未结 8 875
陌清茗
陌清茗 2020-11-28 09:56

Here are the inputs I want to loop through

Main photo:   
Side photo 1: 

        
8条回答
  •  一个人的身影
    2020-11-28 10:44

    I have struggled with this dilemma for almost a week! Nothing I found on the net could help me. I knew sort of what to do, but could not figure out how to loop through the $_FILES array properly - until now when I read the edited post of the accepted answer.

    I made some changes though, in the script as posted, as it did not work properly for me. I wanted to be able to determine if a file was selected at all, so I changed the line "if( !empty( $_FILES[ 'image' ][ 'error' ][ $index ] ) )" to "if( !empty( $_FILES[ 'image' ][ 'size' ][ $index ] ) )" and then instead of "return false;", I put the size into a variable instead: "$Size = $_FILES[ 'upload' ][ 'size' ][ $index ];"

    This way I could check if the $Size variable was larger than zero. If it was, then a file had been selected and I could continue with counting the number of files and do the actual upload. I did not use any of the "unnecessary" script after "return false;", in the accepted answer. Hope this helps someone.

    : P /MacD

提交回复
热议问题