|
Hi,
I am new here and bit confused with one of my php projects.
Any help is highly appreciated.
My Problem :
I want users to upload multiple files at a time and store the data in mysql.
I have done this for one file, where in user can upload one file and the
data is processed and inserted to mysql...
My question is how can i do the same for multiple files.
My HTML Codes and php code to upload one file is as follows :
________Html Codes ____________________________
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="upload.php">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile" size="20">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
___________________PHP CODES _________________________
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("pj1") or die(mysql_error());
mysql_query("CREATE TABLE usrfiles(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
)")
or die(mysql_error());
$query = "INSERT INTO usrfiles (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
echo "<br> New File Created with data<br>";
}
?>
_______________________END CODE_________________
Julie
|