hashing file name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

hashing file name

Post by m2babaey »

Hi
i noticed file uploads hash the file names. why do they do this? or maybe i didn't get that correctly
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I'm not completely sure, but it's like a signature. It helps you avoid running viruses by comparing the signature of the file that you downloaded with the signature that they tell you is valid. Combined with the correct file size, I'm sure it's extremely difficult to duplicate the same signature in a virus as the valid file.
RhapX
Forum Commoner
Posts: 30
Joined: Mon Dec 05, 2005 5:24 pm
Location: Seattle, Washington

Post by RhapX »

They do it so there isn't a duplicate of it on the server. Usually I will rename a file to the timestamp. That way you know when it was uploaded and there will be no duplicate or overwriting going on.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

RhapX wrote:Usually I will rename a file to the timestamp. That way you know when it was uploaded and there will be no duplicate or overwriting going on.
What if two files are uploaded at the same time?
RhapX
Forum Commoner
Posts: 30
Joined: Mon Dec 05, 2005 5:24 pm
Location: Seattle, Washington

Post by RhapX »

It has an _ and then the number of the file from the batch:

1187665966_1.ext
superdezign wrote:
RhapX wrote:Usually I will rename a file to the timestamp. That way you know when it was uploaded and there will be no duplicate or overwriting going on.
What if two files are uploaded at the same time?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I do somewhat the same for images

Code: Select all

$name = time() . substring(md5(microtime()), 0, rand(5, 10) . $ext;
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply