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

**URL:** <https://www.phphelp.com/t/while-uploading-a-file-only-variables-should-be-passed-by-reference-in-c-xampp-htdoc/35966>\
**Category:** Beginners - Learning PHP\
**Created:** [January 3, 2024, 4:36pm UTC](https://www.phphelp.com/t/while-uploading-a-file-only-variables-should-be-passed-by-reference-in-c-xampp-htdoc/35966 "2024-01-03T16:36:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ce1c4bb](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@ce1c4bb](https://www.phphelp.com/u/ce1c4bb)\
**Post date:** [January 3, 2024, 4:36pm UTC](https://www.phphelp.com/t/while-uploading-a-file-only-variables-should-be-passed-by-reference-in-c-xampp-htdoc/35966/1 "2024-01-03T16:36:29Z")

</div>

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 ?  
Thx

```auto
<?php
   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size =$_FILES['image']['size'];
      $file_tmp =$_FILES['image']['tmp_name'];
      $file_type=$_FILES['image']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['image']['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';
      }
      
      if(empty($errors)==true){
         move_uploaded_file($file_tmp,"images/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
?>
<html>
   <body>
      
      <form action="" method="POST" enctype="multipart/form-data">
         <input type="file" name="image" />
         <input type="submit"/>
      </form>
      
   </body>
</html>
```

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [January 3, 2024, 4:53pm UTC](https://www.phphelp.com/t/while-uploading-a-file-only-variables-should-be-passed-by-reference-in-c-xampp-htdoc/35966/2 "2024-01-03T16:53:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alexcray](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@alexcray](https://www.phphelp.com/u/alexcray)\
**Post date:** [January 24, 2024, 4:48am UTC](https://www.phphelp.com/t/while-uploading-a-file-only-variables-should-be-passed-by-reference-in-c-xampp-htdoc/35966/3 "2024-01-24T04:48:22Z")

</div>

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