I am attempting to add an "upload" feature to my website (to upload .doc or .pdf files).

Everything was gravy, until I received this error message while trying to upload a PDF file:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /data/15/1/57/127/1383616/user/1484532/htdocs/mb/upload.php on line 15

I have gone through the code several times, and can't figure out what's wrong. Can anyone shed some light on this?

Here's the code snippet I'm using to upload the file and output a summary of the upload (note that "line 15" in the error above corresponds to line 11 in the snippet below):

echo '<strong>File Upload Summary</strong><br /><br />';
$file_dir = "/htdocs/mb/notes";

foreach($_FILES as $file_name => $file_array){
echo "Path: ".$file_array['tmp_name']."<br />\n";
echo "Name: ".$file_array['name']."<br />\n";
echo "Type: ".$file_array['type']."<br />\n";
echo "Size: ".$file_array['size']."<br />\n";

if (is_uploaded_file($file_array['tmp_name'])){
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array['name']") or die ("Upload Failed");
echo "Upload Successful!";
}
}

    When posting PHP code, please use the board's

    bbcode tags - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your post now and add these bbcode tags to help others in reading/analyzing your code.

    Arrays, more specifically items in arrays referenced by string indexes, should not simply appear inside a double-quoted string. If they do, they should be wrapped in braces ( {} ). Instead, I usually escape out of the string and concatenate the array in the middle, like so:

    echo 'Your name is: ' . $row['name'] . '! Hello there.';

      Ok, the double/single quotes answer took care of the syntax error, but now I'm having a problem with the upload directory path.

      The $file_dir variable... this script (upload.php) is located in htdocs/mb/upload.php.

      I want the uploaded file to go into htdocs/mb/notes/

      What would the path for $file_dir be so that it works?

      (The error I keep getting is "no such file or directory")

        The problem is that the directory "/htdocs" doesn't exist. The "/" at the beginning of the path means you're specifying an absolute path, as if "htdocs" was in the root of the filesystem. This is most likely not so; instead, you could use a relative path. If the "notes" folder is in the same directory as this script, a path of "notes/" would be sufficient.

          Write a Reply...