Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count $_FILES upload fields

Status
Not open for further replies.

TanTrazz

Programmer
Aug 18, 2001
54
NL
Hi guys,

Im getting insane. I can't get it working. What i want to do is count the amount of files in the post.

I've got 8 file fields.

Pic 1: <input type="file" name="item_file[]">
Pic 2: <input type="file" name="item_file[]">
Pic 3: <input type="file" name="item_file[]">
Pic 4: <input type="file" name="item_file[]">
Pic 5: <input type="file" name="item_file[]">
Pic 6: <input type="file" name="item_file[]">
Pic 7: <input type="file" name="item_file[]">
Pic 8: <input type="file" name="item_file[]">

So if i upload 4 files, the count has to be 4. It always say i've uploaded 8 files...

var_dump(count($_FILES['item_file']['name']) != ''); //returns 8
var_dump(count($_FILES['item_file'])); //returns 8
var_dump(count($_FILES)); //returns 8

Can someone help me...

TNX TT
 
First,
$_FILES['item_file']['name']) != '' is a boolean, so
var_dump(count($_FILES['item_file']['name']) != '') should not return 8!

Furthermore, I think they are all submitted, but you will have to check the status code for each one. Please see the PHP manual, section "uploading files". I think it is in the "features" main section. It really tells all there is to know. If you still experience problems, check if the temp directory can be used by the web server user.

Finally, I think $_FILES['item_file']['name'] does not exist. Your array of uploads only has numerical indexes (0 to 7)


+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Code:
function getCount($control){
 $count = 0;
 foreach ($_FILES[$control] as $upload){
   if ($upload['error'] === 0){
     $count ++;
 }
 return $count;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top