Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.