Page 1 of 1

base64 for passing file names in query strings

Posted: Fri Oct 13, 2006 5:00 pm
by neophyte
Wondering if anyone has used base64 encoding for passing file names back in a query string as opposed to rawurlencode/urlencode? Good idea? Bad idea? Acceptable?

Posted: Fri Oct 13, 2006 5:12 pm
by dbevfat
well, I guess it would work, but what's the reason to use it?

Posted: Fri Oct 13, 2006 5:25 pm
by neophyte
I've had trouble in the past passing file names around with rawurlencode ... Just want to be sure the string is passed regardless of what it might be named. Consider an image named:

My Grandma's house in july, john, alex and !@ #$ steve eating some'o grandma's cake.jpg

It's a bit long but in this case I don't know what files will be named.

Posted: Fri Oct 13, 2006 5:49 pm
by dbevfat
I see what you mean, but to my knowledge urlencode() should take care of it -- it encodes all non-alphanumeric characters (except -_.), which includes ... well, all of the special chars. I guess there could be a problem with charsets. For example: unicode uses 1 or more bytes for some characters, and I don't know how urlencode works for those.

So, you're supposed to be safe with urlencode(), but since you say you've had problems, I'm not so sure anymore. Can you reproduce the problems?

As for the base64 method, I don't see anything wrong with it in particular, it's very url-safe and all. If you don't have time to bother and feel comfortable with it, use it. :)

Posted: Fri Oct 13, 2006 5:58 pm
by neophyte
I can't actually replicate the problem I've had with urlencode/rawurlencode. I just remember encountering problems with browsers and certain file name combinations. That's part of the reason I posted the thread to see if anyone has had problems with those two functions.

Posted: Sat Oct 14, 2006 4:21 am
by Chris Corbyn
On a similar topic, does anybody have base64 encoder/decoder for JS? It'd be handy in AJAX apps.

Posted: Sat Oct 14, 2006 12:41 pm
by Maugrim_The_Reaper
http://rumkin.com/tools/compression/base64.php

It's the first Google hit, so don't blame me...;)