Jump to content

key() not returning first value on $_FILES


fivestringsurf

Recommended Posts

I'm looping through an html form that uploads files. It works but in trying to make it more sophisticated by listening for certain input names.  Since $_FILES returns a 2d array i need to analyze the keys...any why doesn't the following code work?

 

//this resides inside an isset()
          reset($_FILES); //make sure array starts from beginning ??? not working
foreach($_FILES as $file){
	echo key($_FILES);
	next($_FILES);
	//doa bunch of uploading and re-naming stuff...
}
//returns all keys but #1 "thumb1" ???

 

the html...

 

<form name="uploadnew" enctype="multipart/form-data"  action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
    thumbnail 1 <input type="file" name="thumb1" /><br />
    thumbnail 2 <input type="file" name="thumb2" /><br />
    thumbnail 3 <input type="file" name="thumb3" /><br />
    thumbnail 4 <input type="file" name="thumb4" /><br />
<br />
large 1 <input type="file" name="large1" /><br />
    large 2 <input type="file" name="large2" /><br />
    large 3 <input type="file" name="large3" /><br />
    large 4 <input type="file" name="large4" /><br />
<input type="submit" name="uploadNew" value="upload!"/>
</form>

 

 

reset() appears to be not working for some strange reason?

what am i missing?

Link to comment
https://forums.phpfreaks.com/topic/187789-key-not-returning-first-value-on-_files/
Share on other sites

try:

foreach ($_FILES as $key => $value)
{
   // do what you want with $key and $value
}

 

Thanks catfish...for essentially waking me up!  I've used the key=>value structure a thousand times, but my mind got clouded.  It all works fine now.  I don't know what on earth i was thinking?

 

:) have a good weekend.

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.