Uploading images to Mysql
| From: | William Glenn | Date: | Sun, 17 Nov 2002 18:58:13 +0000 |
| Subject: | Uploading images to Mysql | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-124806@lists.php.net to get a copy of this message | ||
Hey all, need some quick help. I have some code I was trying to get to work but I keep getting this
error:
Warning: fopen("", "rb") - Success in /home/digital/public_html/upload_test.php3
on line 18
Warning: stat failed for (errno=2 - No such file or directory) in
/home/digital/public_html/upload_test.php3 on line 18
Warning: fread(): supplied argument is not a valid File-Handle resource in
/home/digital/public_html/upload_test.php3 on line 18
Here's my code:
<html>
<head>
<title>Store binary data into SQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<?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","","");
mysql_select_db("ipp_products");
$data = addslashes(fread(fopen($form_data, "rb"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO display_images (description,data) ".
"VALUES ('$form_description','$form_data')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
echo "$data";
} 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>
Any ideas?
Thanks,
William Glenn
Import Parts Plus
http://www.importpartsplus.com