在单个输入中上传多个图像

时间:2017-01-10 00:46:47

标签: php indexing upload undefined

我正在尝试使用单个输入创建多文件上传页面。但是当我上传时会显示此消息

  

未定义的索引:文件   C:\ xampp \ htdocs \ tapromtour.com \ admin_panel \ view \ gallery_script.php on   第13行

这是我的上传表格代码:

<form action="gallery_script" method="POST" enctype="multipart/form-data" style="width:950px;text-align:center;">
 <br/><br/>
<input name="title" type="text" placeholder="Give the album name" style="padding:5px; width:500px;" required ="required"/><br/><br/>
 <input type="file" name="attachPhoto1[]" multiple="multiple" required="required"/>
 <br/><br/>
 <input type="submit" name="submit" value="Submit" id="submit" />
</form>

这是我的上传php页面:

<?php
if (isset($_POST['submit'])){
    //file uplaod
   $title = $_POST['title'];
   if(!empty($_FILES["attachPhoto1"]['name'])) {
        $allowedExts = array("gif", "jpeg", "jpg", "png");
        $error_uploads = 0;
        $total_uploads = array();
        $upload_path = '../album/';
        foreach($_FILES["attachPhoto1"]['name'] as $key => $value) {
            $temp = explode(".", $_FILES["attachPhoto1"]['name'][$key]);
            $extension = end($temp);
            if ($_FILES["files"]["type"][$key] != "image/gif"
                && $_FILES["files"]["type"][$key] != "image/jpeg"
                && $_FILES["files"]["type"][$key] != "image/jpg"
                && $_FILES["files"]["type"][$key] != "image/pjpeg"
                && $_FILES["files"]["type"][$key] != "image/x-png"
                && $_FILES["files"]["type"][$key] != "image/png"
                && !in_array($extension, $allowedExts)) {
                $error_uploads++;
                continue;
            }
            $file_name = time().rand(1,5).rand(6,10).'_'.str_replace(' ', '_', $_FILES["attachPhoto1"]['name'][$key]);
            if(move_uploaded_file($_FILES["attachPhoto1"]['tmp_name'][$key], $upload_path.$file_name)) {
                $total_uploads[] = $file_name;
                mysql_query ("INSERT INTO gallery (id, image, title, date) VALUE ('','$file_name','$title',now())");
                header("Location: gallery");
            } else {
                $error_uploads++;
            }
        }
        if(sizeof($total_uploads)) {


        }
        }
    }    

//file uplaod
?>

我不知道上面的代码有什么问题。它看起来很好,但它在我上传图像时显示消息。你能告诉我上面代码有什么问题吗?谢谢你的帮助。

0 个答案:

没有答案