For this, you have to make a field of 'blob'(binary large object) on your mysql database. After then, make a form for upload. The html code for the form is as follows
<form name="form_image" enctype="multipart/form-data" action="upload.php" method="post" >
<input name="MAX_FILE_SIZE" value="2000000" type="hidden">
<input name="imagefile" type="file">
<input name="uploadimage" value="Upload Image" type="submit">
</form>
Now, for server script, the upload.php file will be like as follows
if(isset($_POST['uploadimage']) && $_FILES['imagefile']['size'] > 0)
{
$tmpName = $_FILES['imagefile']['tmp_name'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$query = "INSERT INTO tbl_sup_images(image_content) "."VALUES ('$content')";
if(mysql_query($query))
echo "upload successfull";
}
You must have to be sure that, you have 'write' permission to the folder where you want to save the image/file. otherwise you won't be able to upload, errors will occur.
Subscribe to:
Post Comments (Atom)










2 comments:
I'm getting an error when trying to upload image/photos to mysql db,pls help!!!
Please describe what type of error you are facing..
Post a Comment