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

时间:2014-05-03 15:22:43

标签: php

php code
    

$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;
 } 
 ?>

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

2 个答案:

答案 0 :(得分:0)

尝试以下,

$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()功能。

答案 1 :(得分:0)

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

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

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