Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File attachments: function "fileIsAccessible" does not exclude directories, produces Notice #2782

Closed
JayEn84 opened this issue Sep 30, 2022 · 0 comments

Comments

@JayEn84
Copy link

JayEn84 commented Sep 30, 2022

Problem description

I used a (previously errorneous) script that should attach all files within a directory to a PHPMailer object using addAttachment. The script did unfortunately not exclude paths to (sub) directories. Here is what happens:

If you use the addAttachment function and pass a directory path rather than a file path, then

  • the file_get_contents function produces a Notice file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in ...
  • A zero byte attachment with the directory's name as file name is added to the email.

Code to reproduce

$mail->addAttachment('/some/path');

Suggestion

The function fileIsAccessible uses file_exists to check whether a file path is valid. But this function returns true if the given path is a file or a directory (https://www.php.net/manual/en/function.file-exists.php). The problem could be solved by using is_file instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants