944,196 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3317
  • PHP RSS
Jun 28th, 2006
0

how deposit a picture to MYSQL database

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
shaocpa is offline Offline
26 posts
since Jun 2006
Jun 29th, 2006
0

Re: how deposit a picture to MYSQL database

Look up the super global $_FILES['xxx'] on php.net. Your file and it's info are in it. Assuming your form is correct.
Last edited by noppid; Jun 29th, 2006 at 5:44 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noppid is offline Offline
17 posts
since Jan 2004
Jul 1st, 2006
0

Re: how deposit a picture to MYSQL database

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
BlazingWolf is offline Offline
32 posts
since Feb 2006
Jul 3rd, 2006
0

Re: how deposit a picture to MYSQL database

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!!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
shaocpa is offline Offline
26 posts
since Jun 2006
Jul 4th, 2006
0

Re: how deposit a picture to MYSQL database

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noppid is offline Offline
17 posts
since Jan 2004
Jul 5th, 2006
0

Re: how deposit a picture to MYSQL database

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!
Reputation Points: 10
Solved Threads: 0
Light Poster
shaocpa is offline Offline
26 posts
since Jun 2006
Jul 10th, 2006
0

Re: how deposit a picture to MYSQL database

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

Great work!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noppid is offline Offline
17 posts
since Jan 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: URL Masking in PHP
Next Thread in PHP Forum Timeline: Two domains on the same account





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC