How do I urlencode filenames in an array inside a PHP file?

Posted on 2011-04-29
Last Modified: 2012-05-11
I have a joomla plugin file called sige.php attached here where around line 838 you will find this code:

$testUrl = '<a href="mailto:?subject=Zuenelli%20propone&body='.$mosConfig_live_site.'/plugins/content/sige/plugin_sige/socialshare.php?img='.rawurlencode($mosConfig_live_site.$rootfolder.$_images_dir_.'/Midsize/'.$images[$a]['filename']).'&name='.rawurlencode($title_iptc).'&caption='.rawurlencode($caption_iptc).'"';

//send link via email
$html .= $testUrl.' title="invia link via email" ><img src="'.$mosConfig_live_site.'/plugins/content/sige/plugin_sige/email.png" /></a>';

The jpg files that my client uploads into the folder /Midsize/ mentioned above sometimes have spaces in their names and sometimes they also contain latin characters/accents and this cannot be avoided. The code above works fine as the rawurlencode sorts all other parts of the URL that is generated on the fly in $testURL except for the current file's name which is retreived from the array filename.

So unfortunately when I run this code and click on the email button I get a url that looks like this:

http://localhost:8888/zuenelli/plugins/content/sige/plugin_sige/socialshare.php?img=http://localhost:8888/zuenelli/images/sda/galleries/giorno_librerietavoli/Midsize/Feg - 1 - (2).jpg

This does not work due to the spaces - when this mailto code is launched and the outlook or mail window opens on pc or mac only the first part is clickable and all the parts after the space are just simple text).

Also the last part is being ignored:

The real link should be something link this:

What am I doing wrong?

thanks in advance

Question by:badwolfff
    1 Comment
    LVL 15

    Accepted Solution

    Logic is that i have taken all requested values compressed it and redirected to other page where i extract it and use it. hope it helps u

                 $qry_arr  = $_REQUEST;
                $str_qry         = http_build_query($qry_arr);
                $comp_str        = base64_encode($str_qry);


    and in fetch.php u can get value

     $uncomp_str =  base64_decode($comp_str);
                                   parse_str(html_entity_decode($uncomp_str), $filter_array);;

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now