Saving images to database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Saving images to database?

Post 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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Saving images to database?

Post 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" />
User avatar
dragonsmistress
Forum Commoner
Posts: 44
Joined: Thu Dec 18, 2008 2:03 pm

Re: Saving images to database?

Post 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....
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Saving images to database?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply