:mad: I am gonna store images into mysql tables.
But I am really in stuck with the following codes:
<?php
if(isset($_POST['submit'])) {
@mysql_connect("localhost","","") or die("cann't connect to the server!");
mysql_select_db("costume");
$image=$_POST['image'];
$data=addslashes(fread(fopen("$image","r"),filesize("$image")));
$result=mysql_query("insert into pictures (image)"."values ('$data')");
$id=mysql_insert_id();
print "<p>the current database id is: <b>$id</b>";
mysql_close;
}else{
?>
<form method="post" action="<?php echo $php_self; ?>" enctype="multipart/form-data">
<input type="hidden" max="MAX_FILE_SIZE" value="1000000">
<input type="file" name="image" size="20">
<input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
Every time I get the warnings:Warning: fread(): supplied argument is not a valid stream resource in c:\wamp\www\storeimage.php on line 7
the current database id is: 9
Every time the imgid increases by 1 but the image itself does not holded by the table.
Maybe some tricks I don't know.Thus I altered the codes like below:
<?php
@mysql_connect("localhost","","") or die("cann't connect the server!");
mysql_select_db("costume");
$file="C:/wamp/www/7.jpg";
$data=fread(fopen("$file","r"),filesize("$file"));
$result=mysql_query("insert into pictures (image)"."values ('$data')");
$id=mysql_insert_id();
print "<p>the current database id is: <b>$id</b>";
mysql_close;
?>
I hope this could work. But still it doesn't work.I always get the message:the current database id is: 0
No data added to the table.
Thank you for your replies. 😃