multiple image upload problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fird01
Forum Newbie
Posts: 19
Joined: Mon Apr 07, 2008 11:04 pm

multiple image upload problem

Post by fird01 »

Code: Select all

<?
$errmsg = "";
if (! @mysql_connect("localhost","root","")) {
        $errmsg = "Cannot connect to database";
        }
@mysql_select_db("phone");
 ?>
<html>
<head>
<title># of Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<table width="100%" border="0" bgcolor="#003466" height="100%" > <tr><td align="left" valign="top">
<table width="100%" border="0"  >
<form name="form1" method="post" action="home.php?page=uploadback.php">
  <tr>
    <td>Enter The Amount Of File To Upload</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input name="uploadNeed" type="text" id="uploadNeed" maxlength="2"></td>
    <td><input type="submit" name="Submit2" value="Submit"></td>
  </tr>
  </form>
  
    <form name="form1" enctype="multipart/form-data" method="post" action="home.php?page=uploadback.php">
  <?
  // start of dynamic form
  $uploadNeed = $_POST['uploadNeed'];
  for($x=0;$x<$uploadNeed;$x++){
  ?>
  <tr>
    <td><input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>"></td>
    <td>&nbsp;</td>
  </tr>
  <?
   }
  ?>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit1">
    <input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>"></td>
  </tr>
  </form>
</table>
<p>
  <?
$uploadNeed = $_POST['uploadNeed'];
// start for loop
if($_POST[Submit]=="Submit1"){
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
//$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
        move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'],"latest.img");
        $instr = fopen("latest.img","rb");
        $image = addslashes(fread($instr,filesize("latest.img")));
        $copy=mysql_query ("insert into pix (title, imgdata) values (\"".$file_name."\", \"".$image."\")");
 // check if successfully copied
 if($copy){
 echo "$file_name | uploaded sucessfully!<br>";
 }else{
 echo "$file_name | could not be uploaded!<br>";
 }
} // end of loop
}
?>
</p>
</td></tr></table>
</body>
</html>
ive been using this code to upload mutilple picture.. some how some of the picture did not finish upload.. and at the end some picture were only half upload and some are full.. i dont know what is wrong in the coding..
fird01
Forum Newbie
Posts: 19
Joined: Mon Apr 07, 2008 11:04 pm

Re: multiple image upload problem

Post by fird01 »

bump
Post Reply