### Thread: User-Contributed: PHP, Mysql, and Images

1. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: INSERT problem

Thanks alot!

That did the trick and it worked now.

Next step is to make a project of it with one add and one view page. I would like to make a view page so php can read the database and display all pics in one page with names (thumbs) and when u click on it it takes u to the bigger size pic.

Got any tips or hints?

Thanks
2. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: image on DB vs. filesys.

I found this cooment in:

http://www.faqts.com/knowledge_base/view.phtml/aid/1241/fid/102

--------------------
May 18th, 2000 09:11

Nathan Wallace
Adam Powell, Sinisa Milivojevic, Sasha Pachev

You should use BLOB type. Choose a subtype according to the sizes of
pictures that you intend to store.

If you are using 3.23.xx, you should use load_file(...) function for
storing images.

To get the image back out into a file try "select ... into outfile".

In general though, it's really not worth doing this for performance
reasons... in fact there aren't many reasons to do this at all.

The best way to store these images is on your file system, and only
storing a path to them in the database, we do this in our web site
(http://neopets.com) when kids upload images and text onto the site.
Apache is MUCH better at caching and retrieving files for web use than
mySQL is, or will ever need to be (well unless you can prove me wrong
:).

Consider the two senarious:

to show db images:
- the image is first read from the data file into MySQL record buffer
- from the record buffer the image goes into the socket
- the application reads it from the socket into its internal buffer
- the contents of the internal buffer are forwarded to the user

file system, not even super highly optimized:
- the image is read from the data file into internal buffer of the web
server.
- the contents of the internal buffer are forwarded to the user

-------------------

What do you think?
3. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: image on DB vs. filesys.

I think I disagree. The reason we store them in databases is because we would have to give crazy permissions on our server to let PHP or Apache or whatever upload images and save them on the server. If I could find a way around not chmod'ing a directory to 777 in order to store files on a filesystem I'd do it in a heartbeat over the database method.

For caching, we use mod_rewrite to give the pages and images "filesystem" urls (no question marks or amphersands). This lets the pages cache according to your browser's settings (it also gets rid of the search engine indexing barrier).

The only other option is to create a cgi script to store files on the system. This would require someone developing a distributable system to install the cgi script and give the cgi script a lot of access.

What I've just mentioned is only based on what I've found out. If you have any information on ways that I could get around having to store files in a database I would greatly appreciate it.
4. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: image on DB vs. filesys.

Whom ever wrote that comment is wrong. They probably know nothing about engineering a DBMS and what goes into it.

The file method presented is way over simplified. It will incur alot more disk operations than with a properly designed (and even poorly designed, in most cases) database. Plain and simple. And that alone will govern 60-90% of the performance. That person also forgets that DBMSs have thier own cache and 99% of the time standard filesystem cache algorithms perform extremely poorly in a DBMS compared to DBMS caches, because a DBMS is NOT a filesystem, and therefore standard rules do not apply.

I can go on and on, but I've actually had a class in DMBS design and I'd like to trust what I learned in that class more than some random webpage.

One thing I really hate is when journalists, people that inform other people are wrong. Once, someone in PC Mag was saying that they were looking to change some setting in the registry, but could not find it. But he said, he found it in system.dat. Well folks, system.dat IS the registry. Moral of this story, becuse some one wrote it doesn't make it right.

But thanks for the post though. Don't take anything I wrote personally. I know you just posted an article. =)
5. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: graphics

Exam. this pl.

echo "<img src=/Harmen/phpbin/view.php?image=$full&imageID=$imageID><p>";

create a file caled view.php
create the image/header tag in this file

and the correspondenting code fore the var's

:))
6. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Images, PHP & MySQL

Well that was a cheap way to do the image thing with MySQL. How about one that actually shows you how to get an actual image into MySQL and be able to retrieve it and display it with a web page
7. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: Images, PHP & MySQL

Surely Mr.Roast would like to demonstrate rather than comment solely. Wouldn't that be nice?
8. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: Images, PHP & MySQL

well, i would really like to see the rest of this tutorial...i got the first part, but honestly, the actual inserting the image into MySQL and retrieving it with a web page is what i really want to learn...anyone knows where i can find a tutorial on that? or the second part to this one?
<br />
<br />
<br />

<br />
<br />
<br />
9. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Images, JSP & MySQL

Hi,

Could you pl help to store images in MySQL useing JSP

Thanks

G.Mohanraj
10. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: Images, PHP & MySQL

<p><pre><font color=#008000><xmp>

$result = @mysql_query($sql);
$data = @mysql_result($result, 0,
11. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### PHP

I like php, easy to program.
12. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### work on Windows?

I have a problem with uploading and storing the images on a directory named 'images'on Windows. I think there could be 2 reasons.

Firstly I believe the above script was written mainly for Unix. I am running Windows 98 and it does not have CHMOD 777, is there any equivalent method for allowing access to the directory?

Secondly I think the line
exec ("cp $picture /full/path/to/joesauto/images/$picture_name");
is not for windows. I have tried substituting cp with COPY which is DOS command for copying files and changing the path to C:\\full\\path\\to\\joesauto\\images\\\$picture_name but still it does not work.

I have tried for hours with different combinations but no use. Any suggestion is highly appreciated.

Thank you
13. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Re: work on Windows?

I have the same proble.
What would be the path for the image dir inwin envirorment as well as I don't know what permissions to place on my PHP uploadtemp dir any ideas ANYONE?
14. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### Retreving images

Well, this is a good tutorial to upload images to the server and store image reference in the database. But now, how can I retrieve that image, along with the other info that I’d uploaded and display it on the webpage. Please help!!!!
15. No Profile Picture
guest
Guest
Devshed Newbie (0 - 499 posts)

#### newbie problem

I have followed the instructions to load the picture name rather than the binary image into the MYSQL database. However, when selecting the image from the location and submitting on the form, I end up with an Can't Find Server or DNS error.

I have apache, php, and mysql set up on my desktop. I have run other php scripts which do pull data from a mysql database without any problems so I am mystified by why loading an path to an image is not working.

Any help?

Thanks.