While Uploading a file: Only variables should be passed by reference in C:\xampp\htdoc

When trying to execute this simple PHP code, i received the following error message:
Only variables should be passed by reference in C:\xampp\htdoc" on line 20
Could you please explain why and can i solve this issue ?

      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size =$_FILES['image']['size'];
      $file_tmp =$_FILES['image']['tmp_name'];
      $expensions= array("jpeg","jpg","png");
      if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      if($file_size > 2097152){
         $errors[]='File size must be excately 2 MB';
         echo "Success";
      <form action="" method="POST" enctype="multipart/form-data">
         <input type="file" name="image" />
         <input type="submit"/>

In the posted code, the error is occuring on line 8, at the end() call. This is because -

This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

Share the exact lines of code where the error occurs, including any relevant functions or variables involved in the file upload process.

Sponsor our Newsletter | Privacy Policy | Terms of Service