无法上传文件宽度输出数据库条目

时间:2017-06-02 21:37:45

标签: php

我正在尝试将图像上传到没有数据库条目的文件夹我在谷歌上发现了这个代码,但我不断收到错误,我不知道我的代码是做错了什么。

HTML:

<div class="upload-btn-container">
    <button class="btn bg-red btn-block btn-lg waves-effect">Passport/EID</button>
    <input type="file" name="files[]" class="btn-fake-upload" />
</div>
<div class="upload-btn-container">
    <button class="btn bg-red btn-block btn-lg waves-effect">Visa</button>
    <input type="file" name="files[]" class="btn-fake-upload" />
</div>
<div class="upload-btn-container">
    <button class="btn bg-red btn-block btn-lg waves-effect">Licence</button>
     <input type="file" name="files[]" class="btn-fake-upload" />
</div>
<div class="upload-btn-container">
     <button class="btn bg-red btn-block btn-lg waves-effect">Credit Card</button>
     <input type="file" name="files[]" class="btn-fake-upload" />
</div>

PHP:

if(isset($_POST['btn-addcust'])) {
$valid_formats = array("jpg", "png", "gif", "jpeg", "pdf");
$max_file_size = 1024*1000; //1000 kb
$path = "../"; // Upload directory
$count = 0;
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {     
    if ($_FILES['files']['error'][$f] == 4) {
        continue; // Skip file if any error found
    }          
    if ($_FILES['files']['error'][$f] == 0) {              
        if ($_FILES['files']['size'][$f] > $max_file_size) {
            $message[] = "$name is too large!.";
            continue; // Skip large files
        }
        elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
            $message[] = "$name is not a valid format";
            continue; // Skip invalid file formats
        }
        else{ // No error found! Move uploaded files 
            if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
            $count++; // Number of successfully uploaded file
        }
    }
}
}

错误:

Notice: Undefined index: files in F:\xampp\htdocs\erp\include\addcust.php on line 33
Warning: Invalid argument supplied for foreach() in F:\xampp\htdocs\erp\include\addcust.php on line 33

任何有助于理解的帮助或解释都将受到赞赏。

由于

0 个答案:

没有答案