http://www.perlmonks.org?node_id=184830


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

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: 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...