Parse Error

I am getting a parse error and not sure how to fix it…
Here is the code…


if ($_SERVER['REQUEST_METHOD'] != "POST")
	{                                                                  
		include "upload.html.php";
	}
else	
	{
		switch($_FILES['upload']['error']):
			case UPLOAD_ERR_OK:
				$ext = strtolower(pathinfo($_FILES['name']['name'], PATHINFO_EXTENSION));
				switch ($ext):
					case 'csv':
						$destfile = '\\Files\\csv\\ ' . basename($_FILES['name']['upload'];
						$ret = @move_uploaded_file($_FILES['name']['tmp_name'], $destfile);
						if ($ret === false)
							echo htmlspecialchars('Unable to move file', ENT_QUOTES, 'utf-8')
						else
							echo htmlspecialchars('File moved successfully', ENT_QUOTES, 'utf-8')
					break;
					case 'jpg': case'jpeg':
						$destfile = '../www/Test/Upload/Files/images/' . basename($_FILES['name']['upload'];
						$ret = @move_uploaded_file($_FILES['name']['tmp_name'], $destfile);
						if ($ret === false)
							echo htmlspecialchars('Unable to move file', ENT_QUOTES, 'utf-8')
						else
							echo htmlspecialchars('File moved successfully', ENT_QUOTES, 'utf-8')
					break;
					default:
						echo htmlspecialchars('Invalid File Type', ENT_QUOTES, 'utf-8');
					break;
			break;
			case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE:
				$output = "Incorrect File Size, Please Reupload"
				include 'output.html.php';
			break;
			case UPLOAD_ERR_PARTIAL:
				$output = 'Partial file found, Please reupload';
				include 'output.html.php';
			break;
			case UPLOAD_ERR_NO_FILE: 
				$output = 'No file found, Please reupload';
				include 'output.html.php';
			break;
			case UPLOAD_ERR_NO_TMP_DIR:
				$output = 'Incorrect Directory';
				include 'output.html.php';
			break;
			default:
			break;		

On this line $destfile = '\Files\csv\ ’ . basename($_FILES[‘name’][‘upload’];
notice that there is a space betwee the last backslash and the quotation mark and everything with the variable looks okay…

Now here is the code without that space…


 $destfile = '\\Files\\csv\\' . basename($_FILES['name']['upload'];


Now, the variable name looks like it is a part of the string and not populating the script with the appropriate value… Plus I am getting a parse error on that line. More than likely the two problems are related, but I am not sure…

Why???

= ‘\Files\csv\’ . basename

csv\’ is not doing what you think, ’ will close the string so you can use . but \’ will keep it open (eg for 'doesn\‘t’.$work)

But wouldn’t that cause the string that is being passed to be something like
\Files\csvwhatever.csv instead of \Files\csv\whatever.csv and therefore cause an error?

Besides, I am still getting the parse error on that line even after I took out the last slash…

These parse errors should be hunted with continuous code removing.
Just remove some portions of string to see what part causes an error
And cont brackets then

escape the \

echo ‘files\\’;

Pretty simple:

$destfile = '\\Files\\csv\\' . basename($_FILES['name']['upload'];

replace with:

$destfile = "\\Files\\csv\\" . basename($_FILES['name']['upload'];

PHPycho, try to think before post

:slight_smile: sorry missing closing bracket: )

$destfile = "\\Files\\csv\\" . basename($_FILES['name']['upload']);

try that out, you still need the escape :slight_smile:

Got it all…

Thanks for all the help. It’s fixed. After the slash issue I found that it was copying the file to the folder above where the file was located (not sure why), but once I put the entire filepath into $destfile it worked fine.

Thanks again