Solved

Product image cache issue in online store

Posted on 2004-10-07
6
258 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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 …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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