Solved

Product image cache issue in online store

Posted on 2004-10-07
6
245 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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 …

828 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