-2

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

error Parse error: syntax error, unexpected T_VARIABLE in E:\pemrograman\xampp\htdocs\upload_test\upload_media_test.php on line 4

fikri
  • 17
  • 1
  • 6

2 Answers2

1

Try following,

$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'] gives the name of uploaded file. So basename() function is not necessary here.

Lepanto
  • 1,413
  • 1
  • 8
  • 15
1

Try moving the dot (.) to the line below:

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

Or you could use PHP's HEREDOC or NOWDOC for large strings, as seen here: https://stackoverflow.com/a/1848974/436721

Community
  • 1
  • 1
Felipe
  • 11,557
  • 7
  • 56
  • 103