Page 1 of 1

Parse error: syntax error, unexpected 'FILES' (T_STRING)

Posted: Wed Oct 29, 2014 10:43 pm
by epcs
I am trying to validate my PHP and I receive this error:

PHP Syntax Check: Parse error: syntax error, unexpected 'FILES' (T_STRING) in your code on line 53
if (file_exists($_FILES['upload']['tmp_name']) && is_file($_ FILES['upload']['tmp_name'])) {
PHP Syntax Check: Errors parsing your code

I have tried several changes, but to no avail. Is anyone able to help. My PHP is below for reference. I have made the line red and bold for people to find easily. Thank you for your help in advance.

<?php# Script 11.2 - upload_image.php
// Check if the form has been submitted:
// Check for an uploaded file:
if (isset($_FILES['upload'])) {

// Validate the type. Should be JPEG or PNG.
$allowed = array ('image/jpeg', 'image/jpeg', 'image/JPG', 'image/x- PNG', 'image/PNG', 'image/png', 'image/x-png');
if (in_array($_FILES['upload']['type'], $allowed)) {
// Move the file over.
if (move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/ {$_FILES['upload']['name']}")) {
echo '<p><em>The file has been uploaded!</em></p>';
} // End of move
} else { // Invalid type
echo '<p>Please upload a JPEG or PNG image.</p>';
} // End of isset

// Check for an error:
if ($_FILES['upload']['error'] > 0) {
echo '<p class="error">The file could not be uploaded because: <strong>';

// Print a message based upon the error.
switch ($_FILES['upload']['error']) {
case 1:
print 'The file exceeds the upload_max_filesize setting in php.ini.';
case 2:
print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
case 3:
print 'The file was only partially uploaded.';
case 4:
print 'No file was uploaded.';
case 6:
print 'No temporary folder was available.';
case 7:
print 'Unable to write to the disk.';
case 8:
print 'File upload stopped.';
print 'A system error occurred.';
} // End of switch
print '</strong></p>';
} // End of error IF.

// Delete the file if it still exists:
if (file_exists ($_FILES['upload']['tmp_name']) && is_file ($_ FILES['upload']['tmp_name'])) {
unlink ($_FILES['upload']['tmp_name']);
} // End of the submitted conditional.

$query = "INSERT INTO products (username, password) VALUES (?, SHA(?))";

$statement = $databaseConnection->prepare($query);
$statement->bind_param('ss', $username, $password);


<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<form enctype="multipart/form-data" action="upload_image.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="824000" />
<fieldset><legend>Select a JPEG or PNG image of 512KB or smaller to be uploaded:</legend>
<p><b>File: </b><input type="file" name="upload" /></p>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
<?php include ("Includes/footer.php"); ?>

Re: Parse error: syntax error, unexpected 'FILES' (T_STRING)

Posted: Thu Oct 30, 2014 8:20 am
by Albert Wiersch

I think I see the problem.

Instead of "$_ FILES", use "$_FILES"... that is, remove the space character.

Re: Parse error: syntax error, unexpected 'FILES' (T_STRING)

Posted: Thu Oct 30, 2014 9:37 am
by epcs
unbelievable, no matter how many times you look at it, you can never see the obvious lol.

Thank you very much :)

Re: Parse error: syntax error, unexpected 'FILES' (T_STRING)

Posted: Thu Oct 30, 2014 9:41 am
by Albert Wiersch
You're welcome.

It's happened to us all. :D