Jump to content

is it possible to rename an image after displaying ?


canabatz

Recommended Posts

is it possible to rename an image after displaying it in the browser!

 

like if the image name in the directory are image1.gif ,and i want to rename the file

after displaying the image to some_image.gif ,and when you look at the source of the page

it will show the renamed file that not exist!

 

any suggestions ?

 

thanx

Link to comment
Share on other sites

If you are trying to secure the file, I would recommend using php to load the image through a get variable, that way you can ensure the session exists.  Then that $_GET variable loads the image, and sets the header to an image. e.g. (http://www.site.com/image/?id=34kjdolskfjl2342lk) would lookup that id, load the image, and change the header of the php script to display an image.

Link to comment
Share on other sites

Not sure what you are "really" trying to accomplish. You have to provide the browser with a real URL to display the image (if you want the user to actually see the image). Whatever output you send to the browser needs to have a valid path for the image and it will be available to the user. You can't change it after sending it to the browser.

 

However, there are ways to "mask" the true image name/location on the server if that is what you are tyring to accomplish. You can hide the true location/path of the image by using an image path that goes to a PHP (or similar page) which will get the right image and read the contents to the browser. For example you might have a page called getImage.php which expects an image ID to be passed on the query string. The page could then use that ID to lookup the image in a database and find the location of the image on the server.

 

Example:

 

$imageID = $_GET['id'];
$query = "SELECT path FROM images WHERE id = $imageID";
$result - mysql_query($query);
$image = mysql_fetch_assoc($result);

//Output the image
header('Content-type: image/jpeg');
$imageObj = imagecreatefromjpeg($image['path']); 
imagejpeg($imageObj);

 

Then in the page where you use an image it would look something like this

echo "<img src=\"getImage.php?id=55\">";

Link to comment
Share on other sites

Hi mjdamato!

 

thanx for your long long replay :)

 

so if after i load the page ,how is it going to look in the source of the page?

 

is it going to look like that:  <img src="getImage.php?id=55"> ?

if so ,are the user will be able to copy paste the src"" to see the image, or it will not be possible?

 

thanx!!!

Link to comment
Share on other sites

It'll look like <img src="getImage.php?id=55">.  They will be able to copy it.  If a user is required to login to access the page, you can restrict access to the image if and only if the session is active, but you can't prevent a user from being able to copy source code.

Link to comment
Share on other sites

Yes, as p2grace stated you cannot prevent the user from loading the image independantly (i.e. copying-and-pasting the image url into the browser). I assume you are trying to "protect" your images. If so, stop right now. It is completely impossible to prevent users from getting your images. When a user views a page with images the images have already been downloaded to their PC into the browsers cache. There are many different ways I have seen sites try and prevent people from copying the images and all of them can be easily worked around.

 

I get artwork images all the time for my music collection and not one has prevented my from getting the images I want. The most annoying is where they layer a transparent gif on top of the actual image so when I right-click to copy the image I only get the blank gif. If the "security" they have in place is too much trouble to bother with I just do a screenshot of the page and crop the image out.

 

The only thing you can do is make it difficult for the users to resuse your images as thier own by watermarking them.

Link to comment
Share on other sites

is it possible to load the image from database ,and after it loads to put a delete statement to the data base

to delete the images?

 

so if you copy paste the source of the page it will not show the images , because they all ready deleted!

 

thanx!!

Link to comment
Share on other sites

As I stated in my first post

Not sure what you are "really" trying to accomplish.

 

Technically you could delete the image file after including it on a page AND after the user's browser has downloaded it, but it is no trivial task. You have to first finish the page for the user and then wait some time to actually delete the image. The user's browser has to first receive the page and then download it so the user can see the image. Only after that could you delete the image. This is possible, but it would be a lot of work.

Link to comment
Share on other sites

Thank you mjdamato for everything !!

 

im working on some security project ,and the images are not importent if some one will copy them!

what im trying to acomplish is that the displayed images will be in a different url or in some unknown directory after they have been displayed! some random url! so if you copy the source of the page and pass it to other user then the images will not be displayd ,becuse they are not there any more!!

 

im going to try some thing from all your suggestion and find the way to fit my needs!!

 

 

thanx again!!!

 

Link to comment
Share on other sites

im working on some security project ,and the images are not importent if some one will copy them!

what im trying to acomplish is that the displayed images will be in a different url or in some unknown directory after they have been displayed! some random url! so if you copy the source of the page and pass it to other user then the images will not be displayd ,becuse they are not there any more!!

 

Ok, then, this is what I suggest - I assume you will be using a database as this will make this process much, much easier:

 

1. Have a database table of the images you will be using (i.e. images).

2. Have a secondary table which will be used for each viewing of the images (i.e. temp_images).

3. When a user requests a page with one of these images, use whatever logic you need to determine which image to show and a) add a record to the secondary table with a new unique ID and the ID of the image from the images table. Use the new unique ID in the image src parameter (<img src="showImage.php?id=idFromTempImagesTable">

4. When the browser loads the image tag it will load the image by calling showImage.php. That page should use the tempImage id to lookup the real image path by JOINing the images and temp_images table and using the passed id in the WHERE clause.

5. After showImage.php serves the image to the user it should delete the record from the temp_images table

 

If the user reloads the page or tries to access the image using the path in the image tag they will get a missing image. Although, the original image *may* show depending on how some browsers cache data. But, you can set certain headers to try and prevent that as well.

Link to comment
Share on other sites

mjdamato , thank you very much for every thing!!

 

I wish for everyone that got some issue  to have a good helper like you!

im using allot of forumes and this one is the best i saw until now ,all my issues got resolved in this forum!

people in this forum are very kind !

 

Thank's again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.