I know it is not a good idea to store images in mysql database but I just wanted to try It.
in mysql I created this table:
CREATE TABLE tbl_images (
id tinyint(3) unsigned NOT NULL auto_increment,
image mediumblob NOT NULL,
PRIMARY KEY (id)
);
and here is the php code:
if(isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$query ="INSERT INTO tbl_images(image)VALUES('".$data."')";
$results=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($results);
if($num>0)
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
?>
I have error in sytax of mysql here is the output:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ...\insertimg.php on line 21
<html>
<title>Image</title>
<!--mikhaim ie form me3 upload ghabli benevisim-->
<!-- inbar mikhaim 2 database image ra gharar dahim-->
<form enctype="multipart/form-data" action="insertimg.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" id="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>
</html>