This is a discussion on Storing files and metadata within the MySQL Database forums, part of the Database Forums category; Please, I am a Newbie. My aim is to upload documents, categorize them and add some metadata and store them ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Please, I am a Newbie. My aim is to upload documents, categorize them
and add some metadata and store them in MySQL for later querying and retrieval. I have found a script which upload documents and store them, but I really can't understand how to add metadata like "category" "uploader" "date_uploaded" to each uploaded file. I hope to make this as easy as possible. Here is my script for processing the uploadform and store the uploaded file: <?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); } include 'library/config.php'; include 'library/opendb.php'; $query = "INSERT INTO upload (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); include 'library/closedb.php'; echo "<br>File $fileName uploaded<br>"; } ?> |
|
|||
|
Nosferatum wrote:
> Please, I am a Newbie. My aim is to upload documents, categorize them > and add some metadata and store them in MySQL for later querying and > retrieval. I have found a script which upload documents and store > them, but I really can't understand how to add metadata like > "category" "uploader" "date_uploaded" to each uploaded file. > I hope to make this as easy as possible. Here is my script for > processing the uploadform and store the uploaded file: > > <?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); > } > > include 'library/config.php'; > include 'library/opendb.php'; > > $query = "INSERT INTO upload (name, size, type, content ) ". > "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; > > mysql_query($query) or die('Error, query failed'); > include 'library/closedb.php'; > > echo "<br>File $fileName uploaded<br>"; > } > ?> > You'll need to create more columns in your table - category, uploader and date_uploaded. Then add these to your INSERT statement. However, you'll probably want to create two more tables - one for uploaders and one for categories, then save their in this table instead of the uploader and category id. Google for "database normalization" to get an idea of how to properly normalize your database. It will be a lot easier in the long run if you start out with a properly normalized database. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |