Takins spaces (and other weard characters) out of file name

XUpload related questions

Moderator: admin

Message
Author
Guest
Posts: 18
Joined: Jan 30, 2007 10:41 pm

Takins spaces (and other weard characters) out of file name

#1 Postby Guest » Jan 30, 2007 10:50 pm

Hi all,

What a great product is this XUploader (I've bought the pro version some time ago)

I have one problem, and that is that sometimes users upload files with a space or other weard character in the filename!

I'm using the upload script in combination of ImageMagick, and the problem is that IM does not like spaces or other weard stuff in the filenames (maybe this is a coding problem of one of my PHP pages)

Anyway... Till now I've been using a complicated way of renaming the files when needed with some extra PHP code, but is it maybe possible to do this within one of the XPuploader scripts?

Thank you.

Noel

User avatar
PilgrimX182
Posts: 2182
Joined: Mar 22, 2006 1:39 pm
Location: UFO Lab
Contact:

#2 Postby PilgrimX182 » Jan 31, 2007 6:33 am

Sure. Here goes quick hack:
in upload.cgi find this line:

Code: Select all

my ($fn,$ext) = ($1,$2);


and add after it:

Code: Select all

$fn=~s/\s/_/g;

Guest
Posts: 18
Joined: Jan 30, 2007 10:41 pm

#3 Postby Guest » Jan 31, 2007 12:57 pm

Thank you,

It did the job :-)

dvmoore
Posts: 3
Joined: Sep 13, 2007 3:39 am

#4 Postby dvmoore » Sep 13, 2007 3:43 am

Hello,

This is an awesome product.

I am experiencing the same problem. I need to specifically remove spaces and [email protected]#$%^&* type characters from .mp3 files being uploaded.

I tried to use the hack but my upload.cgi file contains this line:
my ($fn,$ext) = $filename=~/^(.+)\.(.+)$/;

Not this one: my ($fn,$ext) = ($1,$2);

Can I still use the hack? If not can you show me exactly what to do?

Kind Regards,
Dante

User avatar
PilgrimX182
Posts: 2182
Joined: Mar 22, 2006 1:39 pm
Location: UFO Lab
Contact:

#5 Postby PilgrimX182 » Sep 14, 2007 7:29 am

Yes. You can use it.

Also you can use config opotion to define characters you allow only:

filename_rename_mask => 'a-zA-Z0-9' - this will allow alphanumeric only, other chars will be stripped.

dvmoore
Posts: 3
Joined: Sep 13, 2007 3:39 am

#6 Postby dvmoore » Sep 14, 2007 4:38 pm

Great, that worked...what a simple solution!

Thanks javascript:emoticon('8)')

thuyet
Posts: 14
Joined: Nov 04, 2008 11:28 pm

#7 Postby thuyet » Jan 24, 2009 8:44 am

Hello,
First of all, Xupload is really a good soft, thanks.
I use Xupload Pro V3, I can't figure out how to :

1 - Replace space in the file name (with rename method in the configuration),
I've tried to change this line :
my ($fn,$ext) = $fhash->{file_name_orig}=~/^(.+)\.(.+)$/;
with my ($fn,$ext) = $fhash->{file_name_orig}=~s/\s/\_/g; but it seems it is not the good way.

2 - Replace french accentuated characters with the not accentuated one, it is possible ?
i.e : replace àèéç by aeec.
Thanks for helping

thuyet
Posts: 14
Joined: Nov 04, 2008 11:28 pm

#8 Postby thuyet » Jan 26, 2009 6:34 am

thuyet wrote:Hello,
First of all, Xupload is really a good soft, thanks.
I use Xupload Pro V3, I can't figure out how to :

1 - Replace space in the file name (with rename method in the configuration),
I've tried to change this line :
my ($fn,$ext) = $fhash->{file_name_orig}=~/^(.+)\.(.+)$/;
with my ($fn,$ext) = $fhash->{file_name_orig}=~s/\s/\_/g; but it seems to be this is not the good way.

2 - Replace french accentuated characters with the not accentuated one, it is possible ?
i.e : replace àèéç by aeec.
Thanks for helping


PilgrimX182 could you help please, I'm sure it is possible.

User avatar
PilgrimX182
Posts: 2182
Joined: Mar 22, 2006 1:39 pm
Location: UFO Lab
Contact:

#9 Postby PilgrimX182 » Jan 26, 2009 10:47 am

lol, nice try man ;)

1)
Do next: after

Code: Select all

my ($fn,$ext) = $fhash->{file_name_orig}=~/^(.+)\.(.+)$/;

add

Code: Select all

$fn=~s/\s/\_/g;

- this will replace all spaces in filename with underscore.

2) Not sure this will work but you can try:
in same place as 1) add

Code: Select all

$fn=~s/à/a/g;

and same for other 3 chars.

thuyet
Posts: 14
Joined: Nov 04, 2008 11:28 pm

#10 Postby thuyet » Jan 26, 2009 12:07 pm

Thanks so much,
Nothing is impossible with Xupload, but .... ;-)
Ok for replacing spaces with underscore.
ut for accentuated letters, it works but upload time is much much more longer and it seems like it brings my server down.

Code: Select all

$fn=~s/à/a/g;
$fn=~s/é/e/g;
$fn=~s/è/e/g;
$fn=~s/ç/c/g;


Any idea ?

User avatar
PilgrimX182
Posts: 2182
Joined: Mar 22, 2006 1:39 pm
Location: UFO Lab
Contact:

#11 Postby PilgrimX182 » Jan 26, 2009 12:34 pm

don't think these operations could bring your server down. it's just string replace. but not sure if perl can handle these chars in regexp.

thuyet
Posts: 14
Joined: Nov 04, 2008 11:28 pm

#12 Postby thuyet » Jan 26, 2009 1:36 pm

Thanks for your reply, by "brings my server down" I mean slow it down.
I gonna have a try with javascript to replace thoses charaters.


Return to “XUpload”

Who is online

Users browsing this forum: No registered users and 0 guests