i have two files..., one.php: <?php $max_no_img=2; // Maximum number of images value to be set here echo "<form method=post action=addimg.php enctype='multipart/form-data'>"; echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>"; for($i=1; $i<=$max_no_img; $i++) { echo "<tr><td>Images $i</td><td> <input type=file name='img[]' class='bginput'></td></tr>"; } echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>"; echo "</form> </table>"; ?> PHP: addimg.php: <?php while(list($key,$value) = each($_FILES['img']['name'])) { if(!empty($value)) { $filename = $value; $add = "upimg/$filename"; copy($_FILES['img']['tmp_name'][$key], $add); chmod("$add",0777); } } echo "images are uploaded successfully..!"; ?> PHP: <----------> Doubts: 1. Why this is [] in name <input type=file name='img[]' class='bginput'> 2. what was happening hear... in second file while(list($key,$value) = each($_FILES['img']['name'])) { if(!empty($value)) { $filename = $value; PHP: what that list() will do and what is that key and values..., please tell me clearly. Thank you...!
It is array. If you do not have [] in name you will have in "img" field just the latest image. I am not sure without test. _http://www.php.net/each Copy all images from temporary directory to $add directory. $add is path to image folder.
1. img[] Is an array! Also i think it should be like this img[$i] 2. It copies the image to a temp directory if value is not empty
Ya i understood that.., image to a temp directory if value is not empty But my doubt is about while(list($key,$value) = each($_FILES['img']['name'])) ..? each($_FILES['img']['name'] will capture the name of the file.. i think and what about that list($key,$value) i have Google about list () but not understand
to answer the files for upload in $_FILES have an array of settings that are accessible for an image. They can contain size of file and dimensions of the image, extension (gif, jpg etc) and other properties. the routine just allows you access to these properties. Look up $_FILES and you will see