[support] drupal_urlencode() vs urlencode()

Clarke Robin Robin.Clarke at networkrail.co.uk
Tue Sep 30 09:14:14 UTC 2008


Hi,

I hope this list is still running - I haven't received anything in a few days now.

I am new to Drupal and am struggling to work out when I should use drupal_urlencode() and when I should use urlencode(). And is there a urldecode()? I cant find one.

The exact problem I have has to do with putting a filename into a URL as a request parameter. This was being put into a URL without any encoding and worked fine until someone added a file with an & in the name. So I looked into drupal_urlencode(), but it seems to not work, while urlencode() works perfectly.


When I use drupal_encode():
---------------------------

$filename = 'Arm&Hammer.jpg';

$req_param = drupal_urlencode($filename)

The URL for the link produced is:
http://www.xyz.com/download.php?filename=Arm%2526Hammer.jpg

And when I extract the parameter in download.php and use it I get the following error message:

warning: fopen(C:\Program Files\Apache Software Foundation\Apache2.2\drupal_files/images/Arm%26Hammer.jpg) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\download.php on line 10.


When I use urlencode():
-----------------------

$req_param = urlencode($filename)

http://www.xyz.com/download.php?filename=Arm%26Hammer.jpg

download.php is able to extract the request parameter and open the file.


Can someone please explain to me when I should be using drupal_urlencode() and when I should use urlencode().

Thank you

robin

 

**************************************************************************************************************************************************************** 

The content of this email (and any attachment) is confidential. It may also be legally privileged or otherwise protected from disclosure. 

This email should not be used by anyone who is not an original intended recipient, nor may it be copied or disclosed to anyone who is not an original intended recipient. 

If you have received this email by mistake please notify us by emailing the sender, and then delete the email and any copies from your system. 

Liability cannot be accepted for statements made which are clearly the senders own and not made on behalf of Network Rail. 

Network Rail Infrastructure Limited registered in England and Wales No. 2904587, registered office Kings Place, 90 York Way London N1 9AG 

**************************************************************************************************************************************************************** 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20080930/bc4a5424/attachment.htm 


More information about the support mailing list