XUpload - rename files to unique id

Message
Author
tommy
Posts: 9
Joined: Jun 23, 2007 1:12 pm

rename files to unique id

#1 Postby tommy » Jun 23, 2007 1:24 pm

Hi!

I've tested xupload (Free version), and I'm really impressed!
I think I'll order the pro version, but I have one problem:

What I have to change in upload.cgi to rename _every_ file to a (really) unique id (for example: file.ext should be renamed to 2DQ4MHk8YVD28TX1)

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#2 Postby PilgrimX182 » Jul 04, 2007 7:52 am

It's easy hack. In upload.cgi find

Code: Select all

my ($fn,$ext) = ($1,$2);
and add below it:

Code: Select all

my @range = ('0'..'9','A'..'Z');
$fn = join '', map $range[rand($#range+1)], 1..10;
$ext='';
this will set filename as random string of 10 chars(alphanumeric,uppercase) with no extension.

tommy
Posts: 9
Joined: Jun 23, 2007 1:12 pm

#3 Postby tommy » Jul 21, 2007 5:23 pm

I purchased the pro version now, and I added the code below

Code: Select all

my ($fn,$ext) = ......... 
and it works fine!
Thanks for your help!

tommy

virtuexru
Posts: 3
Joined: Jul 31, 2007 7:05 pm

#4 Postby virtuexru » Jul 31, 2007 7:06 pm

Can you clarify which part of this needs to be changed??

Code: Select all

   my ($fn,$ext) = $filename=~/^(.+)\.(.+)$/;
   $fn=$filename unless $filename=~/\./;

   $fn = substr($fn,0,$c->{max_name_length});