user2891491
user2891491

Reputation: 361

File name with special chars

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

Answers (2)

Phil
Phil

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

user3119231
user3119231

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('ü', '&uuml', $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&uumlr%20alle%20Mitglieder.pdf"

Upvotes: 2

Related Questions