gpt4 book ai didi

php - 函数开始时出现解析错误 : syntax error, 意外的 T_VARIABLE

转载 作者:行者123 更新时间:2023-12-02 00:06:33 24 4
gpt4 key购买 nike

我在网上查看了这个错误,它主要是说你缺少一个分号,但我找不到任何缺少的分号,我希望你们能帮助我。

<?php // add_file.php
require 'log.php';
require 'dictionary.php';
function add_file($file = $_FILES["file"], $tags = $_POST["tags"] ){ // Parse error: syntax error, unexpected T_VARIABLE
$tags = explode(",", $tags);
if ($file["error"]>0){
log("add_file", "Error in file: ".$file["error"], "error");
exit();
} else {
$file["deleted"] = false;
$file["tags"] = $tags;
$file["id"] = uniqid();
$file["ext"] = pathinfo($file['name'], PATHINFO_EXTENSION);
$file["name"] = pathinfo($file['name'], PATHINFO_FILENAME);
$file["tags"][] = $file["ext"];
$file["tags"][] = $file["type"];
$file["tags"][] = explode("/", $file["type"])[0];
$file["date_created"] = date(DateTime::ATOM);
if (file_exists("files/" . $file["id"].".".$file['ext'])){
$file["id"] = uniqid();
$file["loc"] = "files/" . $file["id"].".".$file['ext'];
move_uploaded_file($file["tmp_name"], $file["loc"]);
log("add_file", "Added file at: ".$file["loc"]);
} else {
$file["loc"] = "files/" . $file["id"].".".$file['ext'];
move_uploaded_file($file["tmp_name"], $file["loc"]);
log("add_file", "Added file at: ".$file["loc"]);
}
dict_add("dictionary.json", $file);
}
}

?>

最佳答案

函数的可选参数必须是常量表达式:

The default value must be a constant expression, not (for example) a variable, a class member or a function call.

http://php.net/manual/en/functions.arguments.php#functions.arguments.default

关于php - 函数开始时出现解析错误 : syntax error, 意外的 T_VARIABLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13993878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com