parse error

Simple code but get error message
“Parse error: syntax error, unexpected ‘path’ (T_STRING) in C:\xampp\htdocs\do_upload.php on line 5” :-[

[php]<?php
$file_dir = “C:\Users\alan\Documents\Personal”;

foreach($_FILES as $file_name => $file_array) {
echo "path: ".$file_array[‘tmp_name’].;
echo “name: “.$file_array[‘name’].”
\n”;
echo “type: “.$file_array[‘type’].”
\n”;
echo “size: “.$file_array[‘size’].”
\n”;

if (is_uploaded_file($file_array[‘tmp_name’])) {
move_uploaded_file($file_array[‘tmp_name’], “$file_dir/”.$file_array[‘name’])
or die (“Couldn’t move file”);
echo “File was moved!”;
} else {
echo “No file found.”;
}
}
?>[/php]

Do you use a proper editor? If so you would see that everything after the first line looks strange.

You can even see it here, compare the following code to yours.

[php]<?php
$file_dir = “C:\Users\alan\Documents\Personal”";

foreach($_FILES as $file_name => $file_array) {
echo "path: ".$file_array[‘tmp_name’].;
echo “name: “.$file_array[‘name’].”
\n”;
echo “type: “.$file_array[‘type’].”
\n”;
echo “size: “.$file_array[‘size’].”
\n”;

if (is_uploaded_file($file_array['tmp_name'])) {
   move_uploaded_file($file_array['tmp_name'], "$file_dir/".$file_array['name'])
      or die ("Couldn't move file");
      echo "File was moved!";
} else {
   echo "No file found.";
}

}
?>[/php]

The fix was to change the file dir
from C:\Users\alan\Documents\Personal"
to C:\Users\alan\Documents\Personal""

When writing " you are actually escaping the quote, so PHP will parse no quote instead of slash+quote.

Sponsor our Newsletter | Privacy Policy | Terms of Service