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

created two files: “index.html” and “upload.php”.
The “index.html” contains a form for sending files as shown below:

Send this file: ------------------------------------------------------------------------------------- The contents of the file "upload.php" is shown below: ------------------------------------------------------------------------------------- <?php $uploaddir = 'C:\Users\UserName\Documents\uploads\'; $uploadfile = $uploaddir.$_FILES['userfile']['name']; print "
";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
print "The file is valid and do run with success!";
print_r($_FILES);
} else {
print "Error!";
print_r($_FILES);
}
print "
"; ?> ------------------------------------------------------------------------------------- I changed the following fields in the php configuration file called "php.ini": ------------------------------------------------------------------------------------- max_execution_time=60000000000

max_input_time=60000000000

memory_limit=1024M

post_max_size=1024M

upload_max_filesize=1024M

I did it so I could upload files up to 1GB.
However, when performing the procedure for sending files by the browser, the file “upload.php” returns the following error messages:

Parse error: syntax error, unexpected ‘userfile’ (T_STRING) in C:\Users\UserName\Documents\scripts\upload.php on line 7

What do to do upload files?

Did you show the entire code for upload.php as the error is meant to be on line 7 but it’s not?

Clear upload.php and put in:

[PHP]

<?php print_r($_POST); ?>

[/PHP]

What is the output?

Array ( [MAX_FILE_SIZE] => 1000000000 )

How does this look:

[PHP]

<?php if (isset($_POST['submit']) && isset($_FILES['userfile']) && ($_FILES['userfile']['size']>=1)){ //There is a file and the size is more than 1 so we can guarantee something is here //Create an error array $errors = array(); //Restrict the file size $maxsize = 1000000000; //This is what you originally set in your form -- I decided to process the file size here as it doesn't really belong in the form //Lets restrict it to an image -- we can change this to whatever you want to limit it to $acceptable = array( 'application/pdf', 'image/jpeg', 'image/jpg', 'image/gif', 'image/png' ); if(($_FILES['userfile']['size'] >= $maxsize) || ($_FILES["userfile"]["size"] == 0)) { $errors[] = 'File too large. File must be less than 1GB.'; } if(!in_array($_FILES['userfile']['type'], $acceptable) && (!empty($_FILES["userfile"]["type"]))) { $errors[] = 'Invalid file type. Only PDF, JPG, GIF and PNG types are accepted.'; } if(count($errors) === 0) { //Everything is good, upload with a unique name to prevent duplicates if (move_uploaded_file($_FILES['userfile']['tmp_name'], '' . $_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $_FILES['userfile']['name'].time() . '')){ echo "Success!"; } } else { foreach($errors as $error) { echo ''; } die(); //Ensure no more processing is done } }else { ?>
<form method="post" action="?" enctype="multipart/form-data">
	<label>Select a file <input type="file" name="userfile"></label>
	<input type="submit" name="submit" value="Submit">
</form>
<?php } ?>

[/PHP]

I just want to add that up to 1GB is a really large file, I think you would be better using some kind of chunk uploading. Plupload is quite good: http://plupload.com/

Sponsor our Newsletter | Privacy Policy | Terms of Service