Secure files and display them as well - php

My question is about HTML and PHP.
This is my setup right now:
A website where user have accounts
A FTP server with pictures (currently none)
Files are currently saved on the website in the "PICTURES" folder (which is accessible by everybody who know the full URL)
So, I would like to know how I can display the images without storing them on the website (which will fix my URL problem).
My idea was to move the files on the FTP server, and when a users logon and request a page with those images, download them through a FTP connection, save them on the website, display the images, and remove them. Which would make them accessible only between the downloading time. But this solutions sounds REALLY bad to me.

You need always to have a place where your images are stored. But, if you don't want to give a user the chance to know where are stored, you can create a system which is used to show the images.
Think about this, if you want to download a file from Mega, you can't access to the URL where the file is stored, instead of that, the server itselfs calls a system who assign you a "key" and you can download the file only through that system using your "key".
You could use a system like "base64" so you can encode your image, and show it using it, or, you can use the "header" modifier so, you can display an image using a PHP code.
For example your image tag will be like:
<img src="processImage.php?id=01&user=10&key=123" />
So, your processImage will return a "tricky" image, actually not the image, but the code processed by PHP will be returned, like using "imagejpg()" function with the header "Content-Type:image/jpeg" and then the user will not know where the image is stored actually but the img will works actually.

Related

Make HTML code show all pictures in a folder from FTP?

basic html code user here, just trying to get some scripts finished up and im struggling.
I have a hosted website, and a hosted dedicated server. I have a folder on my dedicated server full of pictures (screenshots) from server players that gets taken randomly. Its for anti cheat.
Basically, ive been trying to write a script so that on a webpage on my hosted website, it automatically shows all the pictures from that folder on my dedi.
Im struggling.
The only code i know to show a picture from ftp is
img src="ftp://username:password#my_ftp_ip_address/Images/imagename.jpg"
I want to create something that automatically shows all the pictures or at least lists the folder directory so that i can click on the pictures, but im a bit confused on how to do this! Any help would be great thanks!
This is basically an anti-pattern. You shouldn't be exposing your username and password in your HTML code.
One thing you can do, is set up a web server on your FTP server so instead of <img src="ftp://..." /> you'll be using <img src="https://my-server.com/image.jpg" />
For example you can set up nginx or apache to serve the images from a certain directory but prevent directory listings.
For nginx, you can either follow the official docs, or get a hint from this SO Question
Same thing with apache, you can pick whichever you find that fits your needs best.
With using <img src""></img> you can target the folder directly without having to insert a link. Like so: <img src"<folder holding images>/<image name>" /> this should target the photo you are looking for without having to expose your username, password, and FTP information.
If you want to show all images it needs to be defined in your HTML, you need to use the code above to target each image individually (Helps organization).
If you want to be able to click on the photos you can add and that should allow you to click on the image and then open it in a bigger version. If you want to make it open in a new tab add this target="_blank" to your <a></a> tag so that way it opens in a new tab.

un downloadlabel images and videos PDF

I am creating a php script for images and videos. The image and videos is uploading and displaying fine on the webpage.
I want to secure the uploaded files, means visitors can't download the files at local system.
There is any one have knowledge how we secure files.
Please help!!!
i am pretty sure what you want is near impossible since if you want your visitor to view the image/video, the browser still need to download it before it can display to the end user.
if the browser can 'download' the data, pretty sure everyone can write small code to grab the data.
if you want to protect from linking to the data directly, you can prevent hot-link through htaccess (for apache) rule.

How to show images in a webpage from root directory in PHP Codeigniter?

I have made a site with Codeigniter and users have options to upload their photos there. As the photos are personal, I think keeping them on web directory is not safe. As a result, I kept them on a root directory like /var/www/images directory. Now, how I can get the images in a webpage?
Wrong Choice dear learner. you images folder needs to be accessible by your code and to the browser to render that image by the image path. For example
This is the image directory of my project. I am using all these images in different pages of my website. Some are selected dynamically by my code.
Now in your case by putting images in www folder, you are making a path of http://images/ which is not recommended by any PHP guidelines. Your images folder should be in your project root not outside.
If you want to disable folders to be viewed, just add empty index.html file, but if you try to protect images from being viewed then your website wont be able to find them too image protection in codeigniter
The code will be as safe as you make it. Well what you are doing is fine, the web server will still have to access the images.
While ignoring the rest of your code or what yo are trying to achieve, you could try referencing the images fro your webroot or probably create a symlink.
Also, I would try to put the images in another place like AWS.
If security is a concern for you, you can try building a ImagesController that checks if image exists, if user has permissions to see it and after that render it.
Uploaded images should also have some reference row inside a table in your database that can have a column which specifies if it should be public (also try to sort them to folders depending on what it represents - user profile pics, product images, etc).
I know it's a little bit of work but this would be the way I would do it.
You can check online for examples of controllers that return an image.
Good luck on your project.

Show cross-domain image via php

I have a script that displays the images via php. www.maindomain.com/image.php?img=test.jpg serve images, and i have other sites, where these images are displayed like this
<img src="www.maindomain.com/image.php?img=test1.jpg">
But this script, for show image is on my www.firstsite.com and www.secondsite.com. Is posibble to log which site is showing image? (put it to database for example).
I know, i can use $_SERVER['HTTP_REFERER'] but it's not 100%. Any other ideas?
The only 100% failsafe way to do it is to share the same image with different URLs. F.i. www.maindomain.com/image.php?test1.jpg&ref=first and www.maindomain.com/image.php?test1.jpg&ref=second. As actually this images are not requested by first or second servers but by visitor's browsers. Having different GET params in URL makes it easy to log data you need.

Displaying images in webpage from HTML

I have a script where by users upload an image on a website and the image gets uploaded to an FTPServer. The name of the file is stored in a database, so when users click on a link, the query string is used as a reference in the Database to get the image name. The only part I'm stuck on right now, is how to display the image on my webpage using php. Is there a specific function to get a copy from the FTP server and display the image? I dont want do download the image to the web server, and then display the image and then delete it, as this could take up a lot of space if the web site has many visitors.
The "big image hosts" typically have web access to their "storage servers" as well. So when a file is uploaded to their image server it's accessible with a URL. You'd want to determine the url that points to the file you just uploaded and place that in your html (in the img tag. Let the user's browser retrieve the image, as opposed to your web server first retrieving it and then displaying the page.
You have to store the image on the web server, once you do that you can display it on your web page however you like, php, ajax, javascript, your choice.

Categories