Bluehost.com Web Hosting $6.95

Storing files and metadata

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-25-2007
Nosferatum
 
Posts: n/a
Default Storing files and metadata

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>";
}
?>

Reply With Quote
  #2 (permalink)  
Old 04-25-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Storing files and metadata

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
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0