base64 for passing file names in query strings

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

base64 for passing file names in query strings

Post 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?
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

well, I guess it would work, but what's the reason to use it?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post 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. :)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

On a similar topic, does anybody have base64 encoder/decoder for JS? It'd be handy in AJAX apps.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

http://rumkin.com/tools/compression/base64.php

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