bug #36304 Check whether path is file in DataPart::fromPath() (freiondrej)
This PR was submitted for the 5.0 branch but it was squashed and merged into the 4.4 branch instead.
Discussion
----------
Check whether path is file in DataPart::fromPath()
| Q | A
| ------------- | ---
| Branch? | 5.0
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
Method `getBody()` uses stream_get_contents() to retrieve the body, however it fails to do so when the stream is a directory.
Commits
-------
9e3670e140
Check whether path is file in DataPart::fromPath()
This commit is contained in:
commit
030b10ca0d
@ -56,6 +56,10 @@ class DataPart extends TextPart
|
|||||||
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
|
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false === is_readable($path)) {
|
||||||
|
throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
|
||||||
|
}
|
||||||
|
|
||||||
if (false === $handle = @fopen($path, 'r', false)) {
|
if (false === $handle = @fopen($path, 'r', false)) {
|
||||||
throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path));
|
throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user