Jump to content

How do I upload many images with one html form?

- - - - -

  • Please log in to reply
No replies to this topic

#1
balamberas

balamberas

    Newbie

  • Members
  • Pip
  • 4 posts
Hi, I need help to upload five images to a web hosts directory. i have three stages below. maybe ive made something wrong.

1) html form.
2) php script to handle form
3) to display the uploaded image
<form name="frmTerms" method="post" action="handle_form.php" id="frmTerms" onSubmit="return checkTerms();" enctype="multipart/form-data"> 

<td height="24"><div align="right"><label for="file">Ad Photo:</label></div>
<td><input name="MAX_FILE_SIZE" value="2000000" type="hidden"/>
<input type="file" name="image" id="image" />
<tr>
<td height="24"><div align="right"><label for="file">Ad Photo:</label></div>
<td><input name="MAX_FILE_SIZE" value="2000000" type="hidden"/>
<input type="file" name="image1" id="image1" />
</tr>
<tr>
<button type="submit" name="formSubmit" value="Submit" id="formSubmit">Submit</button>

if (isset($_FILES['file']) and $_FILES['file'] == 1){
}
$name = $_FILES["file"]["name"]; 
$type = $_FILES["file"]["type"];  
$size = $_FILES["file"]["size"]; 
$temp = $_FILES["file"]["tmp_name"]; 
$error = $_FILES["file"]["error"]; 
 
if ($error >0)
   die("Error uploading file! Code $error.");
 
else
 
{
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
 
move_uploaded_file($temp,"upload/". $name);
 echo "Upload complete";
 
}
 
}
}

 <tr> 
          <td colspan="3" rowspan="4"><?php $_FILES["file"]["image"]; echo "<img src='upload/$name' width='100%' height='100%'>";?></td>
          <td width="144" height="59"><?php $_FILES["file"]["image1"]; echo "<img src='upload/$name' width='100%' height='100%'>";?></td>
        </tr>
        <tr>

when i use this script the images are just broken.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users