1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Image uploading.., Any body will explain this..?

Discussion in 'PHP' started by actress143, Jun 9, 2010.

  1. #1
    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...!
     
    actress143, Jun 9, 2010 IP
  2. Layoutzzz

    Layoutzzz Greenhorn

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #2
    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.
     
    Layoutzzz, Jun 9, 2010 IP
  3. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    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
     
    roopajyothi, Jun 9, 2010 IP
  4. actress143

    actress143 Peon

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    actress143, Jun 9, 2010 IP
  5. willow2009

    willow2009 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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
     
    willow2009, Jun 10, 2010 IP