Upload photo w/ loc. saved in SQL
Assuming all your pages are already connected to your SQL database, how would you
1. Upload a photo, save to a specified folder & save photo location to database
2. Display that photo on a second page.
At any time, you should be able to go back to page 1, upload a new photo which will in turn replace the old photo, update the database and update the photo displayed on page 2.
I searched and searched but couldnt find much on it. Any help would be greatly appreciated. Thanks!
Re: Upload photo w/ loc. saved in SQL
First, you need to learn how to upload a file. PHP.net provides an easy walk through of how you can do this, seen here.
Once you've built a script that you can upload files with, all you need to do is add SQL functionality. So, when you're using move_uploaded_file() to move the temporary uploaded file to a less-temporary directory, like a public file in a web directory, you can simply send a query to your database logging where that file belongs (and who it belongs to, if you are building something user based -- which I have to assume it is, because if you wish to retrieve it on a second page then you will need to have some kind of identifying factor to tell which picture belongs to which person). If you are doing this user based and you're only allowing them to have ONE image at a time, the easiest way would be to name their file based upon either their user name or their user ID. This way, you wouldn't even really need to store the data in a database, you could simply check if /images/kows.png existed (for me), and if it didn't, you could display a default picture. If you don't want to do this, you can still just store the stuff in the database anyway.
When they go back to upload a new picture, you can check the database to grab the picture location, and then check if it exists. If it does exist, use unlink() to delete it, and then continue on with the script like normal -- except this time, instead of using INSERT to insert a new database entry, just use UPDATE to edit it... or, you could always delete the entry from the database when you unlink(), and then just insert a new one.
hope that makes sense?!