Solved

Product image cache issue in online store

Posted on 2004-10-07
6
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
minichicken earned 125 total points
ID: 12255112
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
ID: 12255139
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
ID: 12255144
unless, of course, I checked the name against the database. hmm.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 12

Expert Comment

by:minichicken
ID: 12255205
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
ID: 12255218
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
ID: 12256489
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

739 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