MattEvers Posted October 2, 2006 Share Posted October 2, 2006 I have got a piece of code that will store a user uploaded pic into a database. Now I want to be able to assign that picture a URL to be displayed at, and give the user that URL. Just not sure how to call it from the database and create a page (with other code that will stay consistent between every picture on the page along with the picture). Thanks for any help. Quote Link to comment Share on other sites More sharing options...
printf Posted October 2, 2006 Share Posted October 2, 2006 It not really a good idea to store images in a database, the only time you should ever do it is because you have to, such as when you have certain host restrictions. It would be better just to store the /path/name.ext in the database and let the server deal with the image request because it's better designed to do so.If your still inclined to use the database, then you will need to make a image script that reads the $_GET request (/image.php?image=999) and fetches the image from the database and then dumps it to the browser using a set of header functions!me! Quote Link to comment Share on other sites More sharing options...
MattEvers Posted October 2, 2006 Author Share Posted October 2, 2006 Thanks for your reply!So when the user uploads the pic, I should have php save it in a directory on my server? Not sure how to do that... I'll have to research that. What is the reason behind no images in databases? I'm a little new to this, so not on the same page with a lot of things just yet. Thanks! Matt Quote Link to comment Share on other sites More sharing options...
printf Posted October 2, 2006 Share Posted October 2, 2006 Image uploading isn't really that difficult. I know it can seem that way if it's your first attempted to coding it. The hardest part is validation, making sure you only allow what you want to be uploaded, because there will be a few people trying to find a flaw in logic, so as to compromise your system. There are many classes that do this, but I am one of the old schooled programmers that doesn't believe a class is the answer to everything.[b]What is the reason behind no images in databases?[/b]Like with anything you do, you try your best to do it using the most logical, resource friendly way. When you store a image in the database, and serve it dynamically, you have to use (2) queries just to serve that image.'1. get the (id) to load into the image tag2. call the image script that runs the query to fetch the image!The other way, you run (1) query, the server can then pass the image information to the browser (last modified). If the user has already seen the image and it is still in the browser cache, then the server doesn't have to send it again, so it becomes very resource friendly compared to you having to control the process!me! Quote Link to comment Share on other sites More sharing options...
MattEvers Posted October 2, 2006 Author Share Posted October 2, 2006 That makes sense. Thanks for your help! I'm off to learn about storing/uploading images. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.