Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Product image cache issue in online store

Posted on 2004-10-07
6
Medium Priority
?
266 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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.
Suggested Courses

610 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