File Upload : Overwrite existing

June 23, 2005

Often we are asked whether it's possible to prevent Rad Upload from overwriting existing files on the server. The answer is indeed yes.

Having said that, in HTTP file uploads the client has little say in where the file is to be saved or whether an existing file is overwritten. All that is controlled by the server side handler script. All you need to do to prevent a file being overwritten is to add a simple comparion, for example with PHP it is:

if(file_exists($fileName))

In perl it becomes:

if (-e $fileName)

Then we had a special case, a client of ours wanted to place 'default files' in each user's folder. You can think of them as place holders. The files were numbered sequentially. Now if the user attempts to upload a file, and the home directory contains only the place holders (or defaults) they are to be overwritten. Once all the defaults are overwritten each new file being uploaded will result in a new file being added to the folder.

The problem is how do you tell the difference between a default file and a user uploaded file? The answer is simple, make use of the md5 sum for the file. The default files are small in number, it's a small matter for us to generate MD5 sums for all these files and to store them in an array. Then whenever we find that a file exists on the server, we check it's md5 sum with what's on record. If they match we know it's a place holder and it get's overwritten.

A similar approach will of course work for MegaUpload


Posted by raditha at June 23, 2005 3:51 AM
Your Ad Here

 

Jabber  |  Linux  |  mySQL  |  PHP  |  Java  |  Site Map  |  Wiki

Downloads  |  About  |  Links  |  Contact  |  Home

 

Copyright © Raditha Dissanayake 2003 - 2007

Terms of Use  |  Privacy

 

 

June 2005
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30