Link to home
Start Free TrialLog in
Avatar of badwolfff
badwolfffFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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:
&name='.rawurlencode($title_iptc).'&caption='.rawurlencode($caption_iptc)

The real link should be something link this:
http://localhost:8888/zuenelli/plugins/content/sige/plugin_sige/socialshare.php?img=http%3A%2F%2Flocalhost%3A8888%2Fzuenelli%2Fimages%2Fsda%2Fgalleries%2Fgiorno_librerietavoli%2FMidsize%2FFeg%20-%201%20-%20%282%29.jpg&name=Feg%20-%201%20-%20%282%29

What am I doing wrong?

thanks in advance

 sige.php
ASKER CERTIFIED SOLUTION
Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial