Author Topic: Variable passed to each() is not an array or object  (Read 1193 times)

0 Members and 1 Guest are viewing this topic.

Offline cyberdyne2Topic starter

  • Irregular
  • Posts: 16
    • View Profile
Variable passed to each() is not an array or object
« on: July 28, 2010, 07:38:51 PM »
Quote
Variable passed to each() is not an array or object

Getting this error on the following lines. Can anyone tell me why please?


while(list($key,$value) = each($_FILES[images][type]))

while(list(
$key,$value) = each($_FILES[images][size]))

while(list(
$key,$value) = each($_FILES[images][name]))


Many thanks

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Variable passed to each() is not an array or object
« Reply #1 on: July 28, 2010, 07:41:13 PM »
The error is pretty self explanatory. each expects an array or object, none of the arguments you are supplying are.

Try passing just:

$_FILES
['images']


ps: Notice also that indexes are strings and string need to be surrounded by quotes.
« Last Edit: July 28, 2010, 07:42:37 PM by thorpe »

Offline cyberdyne2Topic starter

  • Irregular
  • Posts: 16
    • View Profile
Re: Variable passed to each() is not an array or object
« Reply #2 on: July 28, 2010, 08:00:19 PM »
The error is pretty self explanatory. each expects an array or object, none of the arguments you are supplying are.

Try passing just:

$_FILES
['images']


ps: Notice also that indexes are strings and string need to be surrounded by quotes.

Many thanks thorpe but unfortunately, your suggestion did not fix it and I'm still receiving the same error.  :confused:

The whole function is:
function checkType() {
	

	
while(list(
$key,$value) = each($_FILES[images][type])){
	
	
strtolower($value);
	
	
if(
$value != "image/jpeg" AND  $value != "image/pjpeg" AND $value != "") {
	
	
	
exit(
'Sorry , current format is <b>'.($value).'</b> ,only Jpeg or jpg are allowed.') ;
	
	
}
	
}
	
checkSize();
}

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Variable passed to each() is not an array or object
« Reply #3 on: July 28, 2010, 08:15:46 PM »
I don't think you read my previous reply.

Offline cyberdyne2Topic starter

  • Irregular
  • Posts: 16
    • View Profile
Re: Variable passed to each() is not an array or object
« Reply #4 on: July 28, 2010, 08:18:30 PM »
I don't think you read my previous reply.

Sorry thorpe, I did read it a number of times. The problem is, I didn't fully understand it.  :-\

function checkType() {
while(
"list($key,$value)" each($_FILES['images']['type'])){
strtolower($value);
if(
$value != "image/jpeg" AND  $value != "image/pjpeg" AND $value != "") {
exit(
'Sorry , current format is <b>'.($value).'</b> ,only Jpeg or jpg are allowed.') ;
}
}
checkSize();
}
« Last Edit: July 28, 2010, 08:25:39 PM by cyberdyne2 »

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Variable passed to each() is not an array or object
« Reply #5 on: July 29, 2010, 12:57:29 AM »
$_FILES['images']['type'] is NOT an array or an object. $_FILES['images'] is.

Offline cyberdyne2Topic starter

  • Irregular
  • Posts: 16
    • View Profile
Re: Variable passed to each() is not an array or object
« Reply #6 on: July 29, 2010, 01:00:47 AM »
$_FILES['images']['type'] is NOT an array or an object. $_FILES['images'] is.

Thank you thorpe