Tutorial :parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' [closed]


I need a fresh set of eyes on this. I got this code from someone who said it worked.

Here is the error:

PHP Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\Inetpub\wwwroot\2am\employment\send-email-form.php on line 19   

Line 19 is the first line of GetUploadedFileInfo(). I get the error for line 20 and 21 also. Its obviously with the $file_info array but whats wrong here?

<?php   $max_allowed_file_size = "100"; // this is size in KB   list($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file) = GetUploadedFileInfo();  if(!Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size)) {     exit();  }  LoadUploadedFile($name_of_uploaded_file);  $path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;       include_once('Mail.php');     include_once('mime.php');    ComposeMail($path_of_uploaded_file);      //////////////////// Functions ////////////////////////    function GetUploadedFileInfo() {     $file_info[] = basename($_FILES['uploaded_file']['name']);     $file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);     $file_info[] = $_FILES["uploaded_file"]["size"]/1024;     return $file_info;  }      function Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size) {     if($size_of_uploaded_file>$max_allowed_file_size ) {         echo "Size of file is greater than" . $max_allowed_file_size . " KB. <a href='attachment_email_form.html'>Click Here to upload a smaller sized file.</a>";        return false;     }  $allowed_extension = array("jpg", "jpeg", "gif", "bmp");  for($i=0; $i<sizeof($allowed_extension); $i++) {      $allowed_extension[$i] = strtoupper($allowed_extension[$i]);   }  $type_of_uploaded_file = strtoupper($type_of_uploaded_file);  if(!(in_array(strtoupper($type_of_uploaded_file),$allowed_extension))) {     echo "You have uploaded a file with an extension of " . $type_of_uploaded_file . " . This type is not allowed. Please upload a file with allowed image extensions like jpg, jpeg, bmp, gif. <a href='attachment_email_form.html'>Click Here to upload a file with allowed extension.</a>";     return false;  }     return true;  }      function LoadUploadedFile($name_of_uploaded_file) {     move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "uploads/" . $name_of_uploaded_file);     return true;  }      function ComposeMail($name_of_uploaded_file) {     $name = $_POST['name'];     $user_message = $_POST['message'];     $to = "RecipietnEmail@hotmail.com";     $subject="An email with attachement is sent";     $from = "SenderEmail@hotmail.com";     $text = "A user " . $name . "has sent you this message and an attachment: " . $user_message;     $message = new Mail_mime();      $message->setTXTBody($text);      $message->addAttachment($name_of_uploaded_file);     $body = $message->get();     $extraheaders = array("From"=>$from, "Subject"=>$subject);     $headers = $message->headers($extraheaders);     $mail = Mail::factory("mail");     $mail->send($to, $headers, $body);     echo "Your Email with attachment was sent.";  }  ?>  


Call me crazy, but I tried this and didn't get a parse error - are you sure you're looking at the right file (or the right version of it)?

Edit: then the only thing I can think of is the single quotes are closing a string that's been left open somewhere else.


$file_info is not a function, it's a variable (array).

The code you posted does not have any errors. I copy/pasted it to a php file and run lint: php -l and it reports: No syntax errors detected in test.php


The error message looks like it is expecting an index in $file_info[]. Are you using an ancient version of PHP which doesn't recognize the "[]" syntax for appending to the end of an array?


The error you are receiving suggests a mismatched parenthesis or quotes, however the syntax looks fine. I am able to run that function without error:

  $ php -a  Interactive shell    php > function GetUploadedFileInfo() {  php {    $file_info[] = basename($_FILES['uploaded_file']['name']);  php {    $file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);  php {    $file_info[] = $_FILES["uploaded_file"]["size"]/1024;  php {    return $file_info;  php { }  php > print_r(GetUploadedFileInfo());  Array  (      [0] =>       [1] =>       [2] => 0  )  

@PhiLho php does allow you to dynamically create array variables. However since it is not being properly initialized, you may get unexpected behavior in cases where the variable was initialized elsewhere. But since the variable is isolated inside a function and not globally accessed, it is fine in this case.

  $ php -a  Interactive shell    php > $a = array();  php > $a[] = 'Hello, world!';  php > print_r($a);  Array  (      [0] => Hello, world!  )  php > $b[] = 'Hello, SO!';  php > print_r($b);  Array  (      [0] => Hello, SO!  )  

Also, what version of PHP are you running? My examples use PHP 5.2.8-pl2-gentoo.


Is the browser directly requesting send-email-form.php, or is it accessing some other PHP file which includes or requires send-email-form.php?

If it is the case that another script includes it, check that there are no unmatched characters (parens, quotes, braces, etc) in any PHP code included before this file, or in any inline PHP code in the main file.


Well I figured out the problem.

Not sure what this accomplished but I pushed line 19 down to line 20 leaving a blank line after the 18 line of function GetUploadedFileInfo() {

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »