954,132 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how deposit a picture to MYSQL database

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

<?php
$id=$_POST['id'];
$photo=$_POST['pic'];
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!

shaocpa
Light Poster
26 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

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

noppid
Newbie Poster
17 posts since Jan 2004
Reputation Points: 10
Solved Threads: 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.

BlazingWolf
Light Poster
32 posts since Feb 2006
Reputation Points: 10
Solved Threads: 1
 

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

shaocpa
Light Poster
26 posts since Jun 2006
Reputation Points: 10
Solved Threads: 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.

noppid
Newbie Poster
17 posts since Jan 2004
Reputation Points: 10
Solved Threads: 0
 

thanks a lot noppid !!

i have resolved my question !

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

your this word enlighten me!!
thanks!

shaocpa
Light Poster
26 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

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

Great work!

noppid
Newbie Poster
17 posts since Jan 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You