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" <[EMAIL PROTECTED]>
> Antworten an: [EMAIL PROTECTED]
> Datum: Wed, 7 Jan 2004 20:21:15 -0500
> An: "PHP DB" <[EMAIL PROTECTED]>
> 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~~
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to