Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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 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;


Replies are listed 'Best First'.
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: 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://184830]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2018-05-20 18:10 GMT
Find Nodes?
    Voting Booth?