I can't find any recent tutorials on how I would do this. How would I upload an image to say a database and display it to the webpage securily in PHP?
|
PHP
Creating a secure way to upload and display images only? |
|
Alex from php academy have some video tutorials on thenewboston channel about that if i remember good.. Videos are from 2011 but i think you should watch it and than check in php manual if functions and methods that he use are still good and secure nowdays, i will try to make similar project like he did there, but i am not planing to make it soon because i dont want to start with db's yet.. I can't post link now because i am on my phone but i will send it to you later, also if you find some nice tut that is "fresh" please share with us 👍
Proud to be 100.000 user on HF ![]() (Jan 24, 2016 02:48 AM)gua Wrote: Alex from php academy have some video tutorials on thenewboston channel about that if i remember good.. Videos are from 2011 but i think you should watch it and than check in php manual if functions and methods that he use are still good and secure nowdays, i will try to make similar project like he did there, but i am not planing to make it soon because i dont want to start with db's yet.. I can't post link now because i am on my phone but i will send it to you later, also if you find some nice tut that is "fresh" please share with us 👍 PHPAcademy is indeed a good channel. Sometimes a fail leads to the solution.
Don't upload an image into a database. Upload the file on your server, and store the name. As for making sure they don't upload anything that isn't a image, you could check on the extension. However even this might not be fully save, I do have a piece of code I used a while back. I don't say this is the best way, but it is an option. Note: this is taken from something I made for myself, so this won't work by just copy/paste. Don't ask me how to get it working, just take the information out of the code.
Code public function newImage($image) {
Jan 24, 2016 03:10 PM
(This post was last modified: Jan 24, 2016 03:12 PM by MineSQL.)
Essentially, just ensure the file type is valid, ensure that the uploaded directory is not accessible by the public (outside Web root or permissions), and ensure the file isn't directly accessed, and rather fetched in php and then the headers are modified to mimic a direct link.
Of course, some of these things don't have to be used to ensure moderate security, but by using all the precautions it seriously limits vulnerabilities. Especially with files, as a whole slew of factors come into play when handling them properly compared to a text input. |
|
|



![[Image: 4tAQ4Gf.png]](https://i.imgur.com/4tAQ4Gf.png)
