Tomas-
Finally, a question I can answer. :) First, you build the HTML form. Note
the hidden MAX_FILE_SIZE variable and the "enctype" attribute, both of which
must be present for the upload to work:
<form enctype="multipart/form-data" name="fileupload" method="post"
action="fileupload.phtml">
<input type=hidden name="MAX_FILE_SIZE" value="300000">
<input type="file" name="file">
</form>
Then, you write the PHP code ("fileupload.phtml") that uploads the file into
a MySQL table:
//feed file binary into a string
$fp = fopen($file, "r" );
$file_binary = addslashes(fread($fp,
filesize($resume)));
fclose($fp);
//create db record for this file containing its
name, size, and binary.
//fyi, values for name and size were created
automatically by PHP upon upload
//and are based upon the name you assigned in the
<input> tag, plus a suffix
$query = "INSERT INTO file_table (name, size, bin)
";
$query .= "VALUES ('$file_name', '$file_size',
'$file_binary')";
//connect to db
$mysql_link = mysql_connect("hostname", "login",
"password");
mysql_select_db("dbname", $mysql_link);
//execute query
$file_insert_result = mysql_query($query,
$mysql_link);
Note the use of the "addslashes" function to escape characters in the file
that would otherwise disrupt the insert. I couldn't get the insert to work
without it.
Regards,
Troy
__________________________
Troy Grady, Managing Director
Grady Levkov & Company, Inc.
-----Original Message-----
From: Tomas Garcia Ferrari <tgf@stripped>
To: MySQL Mailing List <mysql@stripped>
Date: Wednesday, June 23, 1999 11:49 AM
Subject: Re: how to import a binary file into the MYSQL tables.
>> > does anyone know how i can insert a binary file into a table.
>> > lets assume that i have a table called img with pic as long blob and
>> > name as varchar(50).
>
>>Hello Mike,
>>
>>Here is a small perl script which should be very helpful to you...
>
>Hi there,
>I'm trying to do the same using PHP3 and its 'File upload support'
>without success... anyone doing this can give me a clue...? (the problem
>is that when I try to open the file to put it inside the database PHP
>just open the first few characters of the file...).
>Thanks,
>
>Tomas Garcia Ferrari
>
>Bigital
>http://bigital.com
>
>