Side Channel

  • home
  • resources
Home › Blogs › kamal's blog

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password

Navigation

  • Books
  • Feed aggregator

Recent blog posts

  • Ubuntu mirrors up and improved!
  • Google-jstemplate: Iterate object with unknown properties
  • nginx https proxypass for php apps
  • sugarcrm & memcache: Doing it Wrong
  • subversion and https in Ubuntu Karmic
  • Drupal: Views block delta converted to md5 hash
  • Ubuntu Server install requires PAE
  • Installing Drupal from command line
  • Drupal: Handling form field weight through CCK
  • minify javascript using Google Closure Compiler
more

angch's location

angch twitter

  • angch: Heading to Brunei. Business class for a change.
more

Drupal urlencode: Dealing with ampersand in filename

kamal's picture

kamal — Mon, 09/11/2009 - 10:31

A bug poping out with some files failed to download, returning 404. Looking closer at the issue, turned out the files that failed contained ampersand "&" in the filename. PHP would translate the "&" in request path as a key in $_GET variable. So something like:-

$ wget http://www.somesite.com/system/files/fm/somefile_with_&_ampersand.pdf

would result in PHP $_GET as:-

array(
  [q] => system/files/fm/somefile_with_
  [_ampersand] =>
)

urlencode'ing' the path is not enough because PHP would still translate that to an ampersand. drupal_urlencode solve this by double encode the path so when PHP try to parse it into $_GET variable it would still see the encoded version. Since we access the path using Drupal's q variable, Drupal alreading take care decoding it to the actual value.

  • drupal
  • php
  • urlencode
  • kamal's blog
  • Add new comment


Creative Commons License

  • home
  • resources

Standard Disclaimer.