Jump to content

Passing filename with spaces as mail attachment w. PHP script


Recommended Posts

Sometime ago I got through David a great little PHP script to attach files selected via Alfred to IBM notes emails. I use it a lot and works fine as long as the file does not contain any spaces in the name. If there are spaces that attachment process does not work. The script is the following:

$files="{query}";$files=explode(" ", $files);
$url="mailto:?";
foreach($files as $f):
$url.="&attach=".urlencode($f);
endforeach;
echo $url;


exec('open /Applications/IBM\ Notes.app "'.$url.'"');

My question - how can the url encode() be modified so that filenames with spaces are also properly inserted into my emails. I've tried looking without success.

 

 

Link to comment

Sometime ago I got through David a great little PHP script to attach files selected via Alfred to IBM notes emails. I use it a lot and works fine as long as the file does not contain any spaces in the name. If there are spaces that attachment process does not work. The script is the following:

$files="{query}";$files=explode(" ", $files);
$url="mailto:?";
foreach($files as $f):
$url.="&attach=".urlencode($f);
endforeach;
echo $url;


exec('open /Applications/IBM\ Notes.app "'.$url.'"');

My question - how can the url encode() be modified so that filenames with spaces are also properly inserted into my emails. I've tried looking without success.

 

Try just modifying the explode() command to look like this...

$files = explode("\t",$files);

That will split the input into parts using a tab as a separator instead of a space.

Link to comment
  • 2 weeks later...

Thanks for your answers (got back from a long trip to try things out). Definitely looks like the explode() command in the script is the culprit. Unfortunately 

$files = explode("\t",$files);

doesn't work either. As an example I tried it on the following filename

 

"ESA PB-EO(2015)16 SAOCOM-CS – Status and Way forward  v3 clean"

 

getting the result "File does not exist" with spaces replaced by plus signs i.e. "ESA+PB-EO/(2015/)16+....". Is there a workaround that you know off to get the filename in a consistent way for the encoding in PHP ?

 

 

Thanks again for your help

 

Mac

Link to comment

The filename appears to be properly encoded. However, it's impossible to say for sure because you haven't actually posted the encoded URI that isn't working. When you ask for help, posting the thing that's actually causing the problem (in this case, your URL) is always a good idea.
 
As a result this is a pure guess, but you could try rawurlencode instead of urlencode.
 
If you'd like more than guesswork, please provide at least an actual example of your script's output.
 
A further issue is that the command open /Applications/IBM\ Notes.app <some URL> is almost certainly incorrect. You probably want open -a IBM\ Notes.app <some URL>, which will open the specified URL with the specified application (note the -a option). Your command doesn't open the URL with IBM Notes, it opens IBM Notes and the URL.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...