Hi All,
Need help in uploading multiple files and renaming them. I want the file to rename to corrensponding text file while uploading. Below is the messy code on which I'm working.
Regards
BW
HTML code
<html>
<head>
<title>Multi</title>
</head>
<body bgcolor="#c2c2c2">
<form method=post action=upload.php enctype='multipart/form-data'><table border='1' width='400' cellspacing='0' cellpadding='0' align=center><tr>
<td><input name="cast[]" type="text"></td><td>
<input type=file name='images[]' class='bginput'>
<br></td></tr><tr><td><input name="cast[]" type="text"></td><td>
<input type=file name='images[]' class='bginput'>
<br></td></tr><tr><td><input name="cast[]" type="text"></td><td>
<input type=file name='images[]' class='bginput'>
<br></td></tr><tr><td><input name="cast[]" type="text"></td><td>
<input type=file name='images[]' class='bginput'>
<br></td></tr><tr><td><input name="cast[]" type="text"></td><td>
<input type=file name='images[]' class='bginput'>
<br></td></tr><tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr></form> </table>
</body>
</html
Handling file
<?php
$cast = $_POST['cast'];
foreach($cast as $casts){
//echo $casts. "<br />";
}
//Variable for file
$name = $_FILES["images"]["name"];
$type = $_FILES["images"]["type"];
$size = $_FILES["images"]["size"];
$tmp_name = $_FILES["images"]["tmp_name"];
$error = $_FILES["images"]["error"];
//$filename1 = $cast .".jpeg";
//$path = "upimg/" . $filename1;
while(list($key,$value) = each($name))
{
if(!empty($value))
{
$filename = $value;
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
$add = "upimg/$filename";
//echo $_FILES['images']['type'][$key];
// echo "<br>";
copy($tmp_name[$key], $add);
//echo $filename. "<br />";
echo $cast . $filename . "<br />";
}
}
?>