Re: MySQL Insert

From: Date: Thu, 08 Jan 2004 01:36:58 +0000
Subject: Re: MySQL Insert
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-32319@lists.php.net to get a copy of this message
hi there are several ways of saving the data within a file. you can save it plain or binary. if you want to save a file in the db i suggest using the field-type BLOB short example: to create the table: CREATE TABLE files ( id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, fileName VARCHAR(255) NOT NULL, data BLOB, PRIMARY KEY (id) ) TYPE=MyISAM the html-form: <form name="saveFile" action="script.php" method="post" enctype="multipart/form-data"> File: <input name="myFile" type="file"> <input type="submit"> </form> the php-script: <?php $con = mysql_connect(....); mysql_select_db(....); if(isset($_FILES['myFile']) && is_uploaded_file($_FILES['myFile']['tmp_name'])) { $data = join('', file($_FILES['myFile']['tmp_name'])); $qry = 'INSERT INTO files ("filename", "data") VALUES ("'.$_FILES['myFile']['name'].'", "'.$data.'")'; mysql_query($qry, $con); } ?> for further info go&see: http://www.php.net/manual/en/features.file-upload.php hth? greetings -ma # life would be easier, if i knew the source code... > Von: "Will W" <will.w@reptilians.org> > Antworten an: php-db-return-32318-grillen=abendstille.at@lists.php.net > Datum: Wed, 7 Jan 2004 20:21:15 -0500 > An: "PHP DB" <php-db@lists.php.net> > Betreff: [PHP-DB] MySQL Insert > > Hello Everyone, > Can anyone tell me how to insert a file, say a .doc, .txt or a .rtf file into > a table from an upload form?? > > Thanks in advance, > ~~Will~~ >

« previous php.db (#32319) next »