Invalid argument supplied for foreach()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Invalid argument supplied for foreach()

Post by $var »

Hi, I'm using the following code in a multiple file upload,
it used to work, but i moved servers and now i get an error in the foreach area:

Warning: Invalid argument supplied for foreach()

Code: Select all

//START IMAGE UPLOAD
		$path = $_SERVER['DOCUMENT_ROOT']."/it/files/".$issueID;
		if(!is_dir($path)) { //if $path isn't a dir
		mkdir($path, 0755); //create it
		}
		foreach( $HTTP_POST_FILES as $aFile )
		{
				copy ($aFile['tmp_name'], $path."/".$aFile['name']) 
					or die (""); 
		}
Any ideas? The form is multi-part, in case that was a thought.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
echo 'version: ', phpversion(), "<br />\n";
echo 'register_long_arrays: ', var_dump(ini_get('register_long_arrays')), "<br />\n";
?>
what does that print?
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

Code: Select all

version: 5.1.2
register_long_arrays: string(0) ""
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You have to use $_FILES instead.
see http://www.php.net/reserved.variables#r ... bles.files
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

you're amazing, thank you.
Post Reply