0

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!

Edited by happygeek: fixed formatting

3
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by noppid
0

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

0

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.

0

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!!!!

0

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.

0

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!

0

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

Great work!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.