上传多个图像文件

时间:2014-06-01 08:42:34

标签: php file upload

我正在制作一个允许用户上传多个文件(图片)的表单。我已经创建了一个文件数组,但代码似乎不起作用。我没有错误,但文件仍未转移到我发送的位置。

    if (empty($_POST) === false && empty($errors) === true){
                $listing_data = array(
                    'title'         => $_POST['title'],
                    'category'      => $_POST['category'],
                    'description'   => $_POST['description'],
                    'name'          => $_POST['name'],
                    'price'         => $_POST['price'],
                    'email'         => $_POST['email'],
                    'keywords'      => $_POST['keywords'],
                    'phone'         => $_POST['number'],
                );

                if(isset($_FILES['file'])){
                        $name_array = $_FILES['file']['name'];
                        $file_temp = $_FILES['file']['tmp_name'];
                        $allowed = array('jpg','png','gif', 'jpeg');
                        $file_extn = explode('.', $name_array);
                        $file_path ='images/listings/' . substr(md5(time()), 0, 10) . '.' . strtolower(end($file_extn));

                            if(in_array(strtolower(end($file_extn)), $allowed) === true){
                                upload_image($file_temp, $file_extn);
                              }
                            }     
                    add_listing($listing_data);
                    header('Location: addlisting.php?success');
                    exit();

            }elseif (empty($errors) === false){
                echo output_errors($errors);
            }

function upload_image($file_temp, $file_extn){
    $file_path ='images/listings/' . substr(md5(time()), 0, 10) . '.' . strtolower(end($file_extn));
    for($i = 0; $i < count($file_temp); $i++){
        move_uploaded_file($file_temp, $file_path);
     }
}

Photos:<br> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input type="file" name="file[]"> <input type="file" name="file[]"> <input type="file" name="file[]"> <input type="file" name="file[]">

0 个答案:

没有答案
相关问题