Page 1 of 1

Saving images to database?

Posted: Tue Jan 06, 2009 6:26 pm
by dragonsmistress
I run a site called the Hatching Dragons and have a lot of people that use my site.

What I want to do is allow them to pull up an image from MY server (don't know how to do that either) let them edit it(by dragging images onto it) then save it. If they need to edit it I want them to be able to pull it up from some type of form and edit and save.

If anyone can help me on this I'd be very appreciative.

Thanks

RP

Re: Saving images to database?

Posted: Tue Jan 06, 2009 6:46 pm
by alex.barylski
1. Upload the image using a form
2. Store the image in a DB field (type BLOB)
3. Create a proxy script which accesses the BLOB and echo's result to user agent

It's not hard but it's more work than just easily walking you through it.

Have you worked with a SQL database before? Do you know how to insert numbers and letters? BLOB data is no different.

A proxy script would look something like:

Code: Select all

<?php
 
  $sql = "SELECT * FROM table WHERE pkid = 3";
  $res = mysql_query($sql);
  $row = mysql_fetch_object($res);
 
  header('Content-TYpe: image/jpeg'); // Wrong but you get the point I hope
  echo $row->rawdata;
Then instead of accessing the images directly like when stored on file you would call the proxy script like:

Code: Select all

<img src="proxy.php?pkid=3" />

Re: Saving images to database?

Posted: Tue Jan 06, 2009 6:50 pm
by dragonsmistress
Yes, I have worked with them before... but none of what you wrote (most of it anyway) makes sense to me~ :oops:
LOL... but yea I know how to insert stuff....

Re: Saving images to database?

Posted: Wed Jan 07, 2009 9:59 am
by pickle
Online image editing is quite tough. I'd suggest making your users download the image, edit it themselves, then re-upload it. For users that don't have image editing software, there are a few free, online image editors you could suggest.

Regardless of the image editing process, there's really no need to store the image data itself in the database. It is much more efficient to store the image in the filesystem, and just have the database keep track of the path to the file.