简体   繁体   中英

move_uploaded_file doesn't work right in loop for

My code is:

for($i = 0; $i < count($_FILES['creative']['name']['icon']); $i++) {
    $name = mt_rand(0, time());
    move_uploaded_file($_FILES['creative']['tmp_name']['icon'] 
    [$i],'creatives/'.$name.'.png');
    move_uploaded_file($_FILES['creative']['tmp_name']['image'] 
    [$i],'creatives/'.$name.'.png');
}

The problem is that in this code only the last move_uploaded_file works and uploads an image.

Can you explain me why the first move_uploaded_file does not work?

You must set another name for image file. In your code you set the $name for both icon and image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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