[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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

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

1 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now