I am so confused with uploading files in PHP

后端 未结 1 1668
礼貌的吻别
礼貌的吻别 2021-01-25 23:51

I have tried reading multiple tutorials, the PHP documentation and have no idea what I am doing.

Here is my form

相关标签:
1条回答
  • 2021-01-26 00:13

    You'd better follow this tutorial: http://www.w3schools.com/php/php_file_upload.asp

    foreach ($_FILES['file'] as $file) {
    
        if($file['error'] == UPLOAD_ERR_OK) {
    
            $check_name = $file['name'];
    
            // I assume you have to use the file type here, not name
            $filetype = checkfiletype($file['type'], 'jpg,jpeg');
    
            $temp_name = $file['tmp_name'];
            $image_name = 'image_' . $file['name'] . '1';
            move_uploaded_file($tmp_name, $upload_dir . $image_name); 
    
        }
    
    }
    

    Your files are in $_FILES['files'] so using foreach you have to go over each element/file and take its data.

    0 讨论(0)
提交回复
热议问题