Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: uploading a file with the same name

by kodo (Hermit)
on Jul 24, 2002 at 13:45 UTC ( #184830=note: print w/ replies, xml ) Need Help??


in reply to uploading a file with the same name

Hi katgirl,

Yes this would work pretty fine. You could use -s instead of -e because most likely you want the file to be overwritten when it's empty. But I usually give the people who want to upload it a message then and ask them to use another name, because in lots of cases people also want to download their files again, and when there are 10 files a la test1.pl test5.pl etc. people might start to wonder which one theirs was.
Another good way is, if you have a username or something to hang the username at the end of the filename before counting numbers up, but that depends on the kind of usage you have for your script...
Oh yea and you could make this one a bit more obfuscating with $imagename = $imagename.++$num;

giant


Comment on Re: uploading a file with the same name
Download Code
Re: Re: uploading a file with the same name
by frankus (Priest) on Jul 24, 2002 at 13:51 UTC
    $num=1; $imagename=$imagename. ++$num while -s "$Data/$category/$imagename";
    Perhaps consider using an MD5 Sum to see if the files are the same too, to negate duplicate uploads ;)

    --

    Brother Frankus.

    ¤

Re: Re: uploading a file with the same name
by katgirl (Hermit) on Jul 24, 2002 at 13:54 UTC
    it's for an image gallery: http://www.queenfans.com/gallery/ so if the person needs to find their picture, they can just look for it. I wrote the entire thing myself, and I'm only just realising some of the things I should have put in there when I started...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://184830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-10-24 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (138 votes), past polls