Skip to content

Commit b20c8a9

Browse files
committed
Ensure file exists before looking size or type
1 parent 0c79a93 commit b20c8a9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Charcoal/Property/FileProperty.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,14 @@ public function mimetype()
282282
*
283283
* @uses finfo
284284
* @param string $file The file to check.
285-
* @return string|false Returns the given file's MIME type or FALSE if an error occurred.
285+
* @return string|null Returns the given file's MIME type or FALSE if an error occurred.
286286
*/
287287
public function getMimetypeFor($file)
288288
{
289+
if (!$this->fileExists($file)) {
290+
return null;
291+
}
292+
289293
$info = new finfo(FILEINFO_MIME_TYPE);
290294

291295
return $info->file($file);
@@ -380,7 +384,7 @@ public function getFilesize()
380384
{
381385
if (!$this->filesize) {
382386
$val = $this->val();
383-
if (!$val || !file_exists($val) || !is_readable($val)) {
387+
if (!$val || !$this->fileExists($val)) {
384388
return 0;
385389
} else {
386390
$this->filesize = filesize($val);
@@ -428,14 +432,14 @@ public function validateAcceptedMimetypes()
428432
$mimetype = $this->mimetype;
429433
} else {
430434
$val = $this->val();
431-
if (!$val) {
435+
if (!$val || !$this->fileExists($val)) {
432436
return true;
433437
}
434438
$mimetype = $this->getMimetypeFor($val);
435439
}
436440
$valid = false;
437441
foreach ($acceptedMimetypes as $m) {
438-
if ($m == $mimetype) {
442+
if ($m === $mimetype) {
439443
$valid = true;
440444
break;
441445
}

0 commit comments

Comments
 (0)