Hello. I am trying to use PHP to upload an image to the SQL database for display in users profiles. However, Dreamhost informs me the fopen/fread options are disabled here and that I must use cURL instead. The problem is, I’ve never had experience with cURL before as this is the first host I’ve worked with that had my normal functions disabled.

So, I’m looking for help and hoping someone can provide some insight. I’ve found tons of cURL tutorials online, however none for what I need.

How do you store images in an SQL database using cURL instead of the normal $_POST/fread/fopen features that I’m used to?

Any help would greatly be appreciated.


I’m confused. You say you want to upload images files into a database. Are these image files being uploaded by a web browser? If that is the case, you need to use move_uploaded_file(). Then open the destination file for reading.

cURL is a library that can be used to request URLs. Thus if the image files are on another web site and you want to copy them that is what you would use. It returns the response contents as a string making reading files unnecessary.

Well, what I’ve got going on is this:

  1. User creates a profile with data and a profile image.
  2. The PHP script stores the data normally, but
  3. I get an error when it goes to store the image.

Here’s my (non-working) script:

$data = addslashes(fread(fopen($form_data, “r”), filesize($form_data)));
$sql = “INSERT INTO bands (band_name, band_contact, band_type, band_locale, band_site, band_myspace, band_password, data,filename,filesize,filetype) VALUES (’$band_name’,’$band_contact’,’$band_type’,’$band_locale’,’$band_site’,’$band_myspace’,’$band_password’,’$data’,’$form_data_name’,’$form_data_size’,’$form_data_type’)”;
$bid = mysql_insert_id();

The error is being generated on the $data line because it works fine when that line is commented out.

Basically, I’d like to store that image on that row along with the rest of the data then call it in when viewing that users profile.

Your previous post had code in it, will this work?


OK now I see why they told you to use cURL. So far I believe they misunderstood your code. I think you must be relatively new to CGI programming.

The code I posted won’t help.

See Handling file uploads

You would then open the temporary file for reading. Or better yet use move_uploaded_file() to move the file to an images directory instead of storing in the database.

:cool: [color=#6600CC]Atropos[/color] |

First of all, thanks for all the help.

Secondly, I am fairly new to this. I know basic PHP, but this is the first time I’ve had to upload/store images in databases. My initial thoughts were to store the images in a directory to keep the database size down, but I wasn’t sure how to do that. I did, however, have experience with storing stuff in databases so I figured I’d go with that approach. It works on 1&1 servers, but not on Dreamhosts, which leaves me trying to find a workaround.

I’ll read over the Handling file uploads site you referred me to and I’ll reply with questions, because I’m sure I’ll have them.

Thanks again.

Okay. The page “Handling file uploads” is pretty much what my form looks like. It then POSTs that data to another .php file which processes it. The previous code I posted was part of this file. So I guess I have that part down. My question now is, say I move the file to a directory, how do I link it to that specific profile ID so it can be called in when users view that profile? And will this work considering they require that cURL thing?

Thanks again!