解析错误:语法错误,第 4 行 E:\pemrograman\xampp\htdocs\upload_test\upload_media_test.php 中的意外 T_VARIABLE

Posted

技术标签:

【中文标题】解析错误:语法错误,第 4 行 E:\\pemrograman\\xampp\\htdocs\\upload_test\\upload_media_test.php 中的意外 T_VARIABLE【英文标题】:Parse error: syntax error, unexpected T_VARIABLE in E:\pemrograman\xampp\htdocs\upload_test\upload_media_test.php on line 4解析错误:语法错误,第 4 行 E:\pemrograman\xampp\htdocs\upload_test\upload_media_test.php 中的意外 T_VARIABLE 【发布时间】:2014-06-20 05:02:08 【问题描述】:

php代码

$target_path1 = $target_path1.basename($_FILES['uploaded_file']['name']);

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path1)) 
    echo "The first file ".basename( $_FILES['uploaded_file']['name']).
    " has been uploaded.";
  else
    echo "There was an error uploading the file, please try again!";
    echo "filename: ".basename( $_FILES['uploaded_file']['name']);
    echo "target_path: ".$target_path1;
  
 ?>

错误 解析错误:语法错误,E:\pemrograman\xampp\htdocs\upload_test\upload_media_test.php 中的意外 T_VARIABLE 在第 4 行

【问题讨论】:

【参考方案1】:

尝试关注,

$target_path1 = $target_path1.$_FILES['uploaded_file']['name'];

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path1)) 
    echo "The first file ".$_FILES['uploaded_file']['name']." has been uploaded.";
 else
    echo "There was an error uploading the file, please try again!";
    echo "filename: ". $_FILES['uploaded_file']['name'];
    echo "target_path: ".$target_path1;

$_FILES['uploaded_file']['name'] 给出上传文件的名称。所以这里不需要basename()函数。

【讨论】:

【参考方案2】:

尝试将点 (.) 移动到下面的行:

echo "The first file ".basename( $_FILES['uploaded_file']['name'])
." has been uploaded.";

或者您可以将 PHP 的 HEREDOC 或 NOWDOC 用于大字符串,如下所示:https://***.com/a/1848974/436721

【讨论】:

以上是关于解析错误:语法错误,第 4 行 E:\pemrograman\xampp\htdocs\upload_test\upload_media_test.php 中的意外 T_VARIABLE的主要内容,如果未能解决你的问题,请参考以下文章

解析错误:语法错误,第 56 行的意外 T_FUNCTION [重复]

错误:“。”处或附近的语法错误第 4 行:在 like.takerId = frame.likeId 上;

解析错误:语法错误,意外的“公共”(T_PUBLIC)[关闭]

kivy-ios .toolchain.py:第 4 行:语法错误:Mac High Sierra 中文件意外结束

-e 第 1 行,“'755']”附近的 nmake 语法错误

第 14 行 '' 附近的 SQL 语法错误