Skip to content

Commit

Permalink
Ensure file exists before looking size or type
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaskill committed Feb 26, 2020
1 parent 0c79a93 commit b20c8a9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Charcoal/Property/FileProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,14 @@ public function mimetype()
*
* @uses finfo
* @param string $file The file to check.
* @return string|false Returns the given file's MIME type or FALSE if an error occurred.
* @return string|null Returns the given file's MIME type or FALSE if an error occurred.
*/
public function getMimetypeFor($file)
{
if (!$this->fileExists($file)) {
return null;
}

$info = new finfo(FILEINFO_MIME_TYPE);

return $info->file($file);
Expand Down Expand Up @@ -380,7 +384,7 @@ public function getFilesize()
{
if (!$this->filesize) {
$val = $this->val();
if (!$val || !file_exists($val) || !is_readable($val)) {
if (!$val || !$this->fileExists($val)) {
return 0;
} else {
$this->filesize = filesize($val);
Expand Down Expand Up @@ -428,14 +432,14 @@ public function validateAcceptedMimetypes()
$mimetype = $this->mimetype;
} else {
$val = $this->val();
if (!$val) {
if (!$val || !$this->fileExists($val)) {
return true;
}
$mimetype = $this->getMimetypeFor($val);
}
$valid = false;
foreach ($acceptedMimetypes as $m) {
if ($m == $mimetype) {
if ($m === $mimetype) {
$valid = true;
break;
}
Expand Down

0 comments on commit b20c8a9

Please sign in to comment.