multiple image upload problem
Posted: Sun Apr 13, 2008 11:42 pm
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> </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> </td>
</tr>
<?
}
?>
<tr>
<td> </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>