how deposit a picture to MYSQL database
below is the code :

<?php
$id=$_POST;
$photo=$_POST;
if ($photo<>""){
$fp=fopen($photo,"r");
$data=addslashes(fread($fp,filesize($photo)));
}
$sql="insert into product(id,pic) values('$id','$data')";
mysql_query($sql,$conn) or die ("插入数据失败: ".mysql_error());
?>

but always unsuccessful! why? plz help me!

Look up the super global $_FILES on php.net. Your file and it's info are in it. Assuming your form is correct.

Not only that you must store the picture as Binary or Blob data type, and you need more than just the data, such as extension(to deteremine what compression is used), and the size.

I suggest you search on google, there are plent of great articles on the net for upload images and stuff to databases.

thanks a lot

when i test this code on my own computer,it is successful.
but when i upload this code to special PHP space it is unsuccessful
why? are you have the same functional code?

pls help me!!!!

Home test beds are useless for development IMO. For that matter, only one server for development can bite ya in the code.

You need to test and develop on a real server and test on more then one server for the best results.

thanks a lot noppid !!

i have resolved my question !

" Look up the super global $_FILES on php.net.
Your file and it's info are in it. Assuming your form is correct. "

your this word enlighten me!!
thanks!

It's good to hear you were able to use the reference and solve your problem.

Great work!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.