Fatal error: cannot reassign a global variable automatically

Fatal error: Cannot reassign the _FILES global variable automatically to C: \ xampp \ htdocs \ user \ utils \ CommonUtils.php on line 1395

Code on line 1395

public static function saveAvatar($code, $pilotid, $_FILES) { 
+4
source share
4 answers

you cannot use $_FILES for function parameter, this is a reserved word, use this instead

 public static function saveAvatar($code, $pilotid, $files) { } 

and to call pass $_FILES as follows

 saveAvatar($code, $pilotid, $_FILES); 

OR

You can also access $_FILES directly without passing it inside a function to a function inside a function.

+10
source

You are trying to set a variable named $ _FILES in a local scpe as an argument to the saveAvatar () method; but can not, because it is one of the special superglobal.

Change the line to

 public static function saveAvatar($code, $pilotid) { 

The superglobal $ _FILES file will still be available for this method simply because it is superglobal

+4
source

I also had a problem. Then I just deleted the $ _FILES variable from the list of variables and my website started working again.

0
source

Usually we cannot reassign $ _Files, which means that we cannot pass an automatic super global variable as an argument to a -or-function. But we have alternative solutions.

Pass the file as a parameter

  function ImageProcess(array $_File){ $image = $_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; //Write your code here... } 

A function call with an automatic global variable as an argument.

  if ($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_FILES['file'])){ echo ImageProcess($_FILES['file']); } } 

Download Form

  <form method="post" action="<?php $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data"> <input type="file" name="file" /> <button type="submit">Update &amp; Save</button> </form> 
0
source

All Articles