faqts : Computers : Programming : Languages : PHP : Common Problems : File Uploading

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

123 of 219 people (56%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How can I let users upload files and store them in a database?
How do I insert a client-side file into a BLOB in an Oracle or mySQL database?

Jan 25th, 2000 10:33
Matt Gregory, Ronell Alberts, Nathan Wallace, Onno Benschop,


Create a form to upload the file using the 
<input type="file" name="ClinetFile"> field item.
Check the php documentation on uploading files for mor information 
onthis.
To insert the file into the database:
<?
//The file is placed in the webservers temp folder...
//use the fopen method to get the file data into a variable...
$filehandle = fopen($ClientFile);
$filedata = fread($filehandle, filesize($ClientFile));
//you must make it compatable with the string type of the query...
$filedata = addslashes($filedata);
//put the data into the blob field...
ora_do("Insert into mydatabase (myblobfield) values ($filedata)");
?>