上传多个文件错误;


Uploading multiple files error;

我在下面有这段代码(我正在处理文件上传)。在本地主机上,它工作正常,但是当我将其上传到我的服务器时,它会返回此错误;

解析错误:语法错误,第 91 行/home/public_html/bookingsuccess.php 中意外的"["

第 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";
        }
    }
}

感谢您的任何回复!

您可能正在使用 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",
];
?>