Forums
This topic is locked
PHP add image
Posted 08 Oct 2002 23:11:59
1
has voted
08 Oct 2002 23:11:59 kathy browning posted:
I recently purchased the PHP Web Development book by Powell, Green and Mairlot. Unfortunately it did not cover the topic of how to upload an image file into a sql server database. Upon visiting a php website, I found the following code, however still am unable to get et to work. I get the errors, unknown variable Submit. Anyone know why this is not working for me? Also, by reading this code can anyone suggest an easier way to manipulate code generated by Dreamweaver MX when using the Insert Record from the Server Behavior /Application Window??>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
// code that will be executed if the form has been submitted:
if ($submit) {
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT("localhost","root","password"
mysql_select_db("binary_data"
$data = addslashes(fread(fopen($form_data, "r", filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</BODY>
</HTML>
Replies
Replied 09 Oct 2002 15:45:54
09 Oct 2002 15:45:54 Brent Colflesh replied:
Dear Kbgeorgia,
Instructions for PHP file uploading are here:
www.php.net/manual/en/features.file-upload.php
Regards,
Brent
Instructions for PHP file uploading are here:
www.php.net/manual/en/features.file-upload.php
Regards,
Brent