Reputation: 361
I'm using SwiftMailer and trying to add an attachment with special chars and spaces in it's filename. How can I add such a file, f.e. "Informationen für alle Mitglieder.pdf"?
I use this command:
$message->attach("resources/assets/docs/Informationen für alle Mitglieder.pdf");
...but I'm getting always an file not found error. When I replace all special chars, it works fine?
Is there any "decoding function" to make it work? For white spaces, I can replace them easily with "\x20" and it works. But what's about the other chars like "äöü"?
Upvotes: 0
Views: 3155
Reputation: 2313
Have you tried using the attach method correctly as per the documentation?
$message->attach(Swift_Attachment::fromPath('resources/assets/docs/Informationen für alle Mitglieder.pdf'));
Also, there is nothing wrong with spaces or extended ascii in filenames. There are not many operating systems which dont support it.
Upvotes: 1
Reputation:
$message->attach("resources/assets/docs/Informationen_fuer_alle_Mitglieder.pdf");
Just rename your .pdf. And don't take special characters and white spaces in your urls in future.
Maybe this is useful for you:
$string = "resources/assets/docs/Informationen für alle Mitglieder.pdf"
$string = str_replace(' ', '%20', $string); // %20 means white space
$string = str_replace('ü', 'ü', $string); // %uuml means ü
echo $string;
EDIT2:
http://www.webspace-finden.de/html-php-ae-oe-ue-und-szett-zeichencodes/
Ä – & Auml;
ä – & auml;
Ö – & Ouml;
ö – & ouml;
Ü – & Uuml;
ü – & uuml;
remove white space behind "&" otherwise I couldn't show this
http://php.net/manual/de/function.urlencode.php
<?php
echo urlencode($string); >;
?>
EDIT3:
$string = "resources/assets/docs/Informationen%20für%20alle%20Mitglieder.pdf"
Upvotes: 2