Solved

Product image cache issue in online store

Posted on 2004-10-07
6
212 Views
Last Modified: 2006-11-17
I have created an online store for a client. I am creating the backend for the store and have included various different pages such as an add product page and an edit product page. The problem I am having on the edit product page is the fact that one the image is edited and the page reloads, the image is still the old one since it uses the same file name.

I have already tried adding random numbers in the URL and after the .jpg?3827958072305. I don't want to store the images in the db. Any suggestions?
0
Comment
Question by:remmuh
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
minichicken earned 125 total points
Comment Utility
Hmm.....

Some stupid method, but it works, or at least it worked for me once.

Everytime you upload the image, you need to create a random number for it with its original file entension. So the browser will always recognize the file as a new file and not cached.

So if you upload a file => my_picture.jpg it will be saved as something like adefg12354dsa12348d54213asdefs54.jpg on the server.
To create that random string you can use md5(uniqid(rand())); to generate a 32 length size randon string.
You will also need to store the file name into the DB in order to reference the image.

Is this something you asking?
0
 
LVL 2

Author Comment

by:remmuh
Comment Utility
hmm, yes I think that could be a good way of doing it, only there is an extremely small chance that another image would get overwritten isn't there?
0
 
LVL 2

Author Comment

by:remmuh
Comment Utility
unless, of course, I checked the name against the database. hmm.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:minichicken
Comment Utility
If you need to overwrite the existing image with the new image,
You will need to retrieve the existing image file name, before you update the new file name to the DB.
And delete the old image with the retrieved file name.

Something like that to work around things... :)
0
 
LVL 2

Author Comment

by:remmuh
Comment Utility
Sorry, what I mean by that was, since it is a random image, there is the very small percentage of a chance that a random number would come up the same as another one. But again, I can just check that against the db to see if there is another image with that name.
0
 
LVL 12

Expert Comment

by:minichicken
Comment Utility
Oh I see what you mean, with md5(uniqid(rand())); I think it is really unique enough, with that you basically, generately a Random , Unique string with the 32 character length MD5 algorithm, with combination of alphabet and numbers.

So I dont think there should be a problem :) but it also good to check the DB, to make sure nothing happens.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now