For some reason i have to put all input field into array.Because the input are dynamically added up to user.
When user click on add button ,will generated the following for upload image
<input type="file" name="product['+n+'][gthumbnail][]" />
But i have no idea how to loop the available array(filled).I don’t even get to count the array size.And these are my working code.Hope every expert out there can point out the mistake I did
//loop for image file upload
foreach($product as $productcount){
....
....
....
//this is what i have now ,and it is not working,error saying the gthumbnail is undefined
for($i=0;$i<sizeof($_FILES['gthumbnail']);$i++){
$m=uploadFile($_FILES['gthumbnail'][$i]);
}
}//End of product loop
print_r($FILES)
Array (
[product] => Array ( [name] => Array ( [1] => Array ( [thumbnail] => [gthumbnail] => Array ( [0] => [1] => [2] => ) [gphoto] => Array ( [0] => [1] => [2] => ) ) ) [type] => Array ( [1] => Array ( [thumbnail] => [gthumbnail] => Array ( [0] => [1] => [2] => ) [gphoto] => Array ( [0] => [1] => [2] => ) ) ) [tmp_name] => Array ( [1] => Array ( [thumbnail] => [gthumbnail] => Array ( [0] => [1] => [2] => ) [gphoto] => Array ( [0] => [1] => [2] => ) ) ) [error] => Array ( [1] => Array ( [thumbnail] => 4 [gthumbnail] => Array ( [0] => 4 [1] => 4 [2] => 4 ) [gphoto] => Array ( [0] => 4 [1] => 4 [2] => 4 ) ) ) [size] => Array ( [1] => Array ( [thumbnail] => 0 [gthumbnail] => Array ( [0] => 0 [1] => 0 [2] => 0 ) [gphoto] => Array ( [0] => 0 [1] => 0 [2] => 0 ) ) ) ) )
why don;t you try with a single dimension array instead of
name="product['+n+'][gthumbnail][]". It looks like very complicated one.may be the following will make your work easier,
When the above form is submitted, the arrays
$_FILES['userfile'], $_FILES['userfile']['name'], and$_FILES['userfile']['size']will be initialized.When register_globals is on, globals for uploaded files are also initialized. Each of these will be a numerically indexed array of the appropriate values for the submitted files.
For instance, assume that the filenames /home/test/review.html and /home/test/xwp.out are submitted. In this case, $_FILES[‘userfile’][‘name’][0] would contain the value review.html, and $_FILES[‘userfile’][‘name’][1] would contain the value xwp.out. Similarly, $_FILES[‘userfile’][‘size’][0] would contain review.html’s file size, and so forth.