mac Posted April 10, 2015 Share Posted April 10, 2015 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
deanishe Posted April 10, 2015 Share Posted April 10, 2015 It looks to me like your problems start in the first line with explode(). This assumes space is the separator between filepaths, so it will turn any path with a space in it into two invalid paths. Link to comment
jdfwarrior Posted April 11, 2015 Share Posted April 11, 2015 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
mac Posted April 22, 2015 Author Share Posted April 22, 2015 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
deanishe Posted April 22, 2015 Share Posted April 22, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now