上传多个文件错误;

时间:2015-03-16 06:15:11

标签: php

我在下面有这个代码(我正在处理文件上传)。 在localhost它正常工作,但当我将它上传到我的服务器时,它返回此错误;

解析错误:语法错误,意外情况' ['在/home/public_html/bookingsuccess.php第91行

第91行,这是下面的第一行代码:

$allowed = ['jpg','png','gif','eps','pdf','doc','docx','xls','xlsx','ppt','pptx','ai','zip','rar'];
$succeeded = [];
$failed = [];
if (!empty($_FILES['file'])) {
    include('config.php');

    foreach ($_FILES['file']['name'] as $key => $name) {

        if($_FILES['file']['error'][$key] === 0){
            $temp = $_FILES['file']['tmp_name'][$key];
            $ext = explode('.', $name);
            $ext = strtolower(end($ext));

            $file = md5_file($temp) . time() .'.'.$ext;

            if (in_array($ext,$allowed) === true && move_uploaded_file($temp, "uploads/{$file}") === true) {
                    print_r($succeeded [] = array('name' => $name, 'file' => $file));
                    $dir = "uploads/{$file}";
                    $qry = $handler->prepare('INSERT INTO store (location, name) VALUES (?,?)'); 
                    $qry->execute(array($dir, $name));
                # code...
            }else{
                $failed[] = array($name);
                echo "Some files failed to upload due to invalid file extensions";
            }

        }else{

            echo "Error";
        }
    }
}

感谢您的回复!

1 个答案:

答案 0 :(得分:1)

您可能正在使用PHP< 5.4。

根据http://docs.php.net/manual/en/language.types.array.php

  

从PHP 5.4开始,您还可以使用短数组语法,将array()替换为[]。

这在手册页上的示例中显示:

<?php
$array = array(
    "foo" => "bar",
    "bar" => "foo",
);

// as of PHP 5.4
$array = [
    "foo" => "bar",
    "bar" => "foo",
];
?>
相关问题