Jump to content

fatal error when looping


newbtophp

Recommended Posts

Im looping through an array of $_FILES using foreach, and then preg_matching  that using if else, if found then run a function on that, however when i have more than 1 file and a match is found and the function runs, it outputs a fatal error can not redeclare function error :o

 

Im not not sure why its doing this since its not the same file...

 

This only happens when more than one file (even though they are different files) call the same function when looping.

 

Here the code:

 

	if(count($_FILES["item_file"]['name'])>0) { //check if any file uploaded
	$GLOBALS['msg'] = ""; //initiate the global message
	for($j=0; $j < count($_FILES["item_file"]['name']); $j++) { //loop the uploaded file array
		$file_name = $_FILES["item_file"]['name']["$j"]; //file name
		$file = file_get_contents($_FILES["item_file"]['tmp_name']["$j"]);
      if(preg_match("~php~", $file)){
      echo php($file);
      } else if(preg_match("~pl~", $file)){
     echo perl($file);
     }

      }
	}
}

 

Any can help me, please. :)

Link to comment
https://forums.phpfreaks.com/topic/194035-fatal-error-when-looping/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.