The expression $uploader->getFilename() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.
In PHP, under loose comparison (like ==, or !=, or switch conditions),
values of different types might be equal.
For string values, the empty string '' is a special case, in particular
the following results might be unexpected:
''==false// true''==null// true'ab'==false// false'ab'==null// false// It is often better to use strict comparison''===false// false''===null// false
Loading history...
26
$uploader->setFilename(uniqid());
27
}
28
29
$fileData = explode(';base64,', $original, 2);
30
31
if (!$uploader->getExtension() && preg_match('|data:\w+/(\w+)|', $fileData[0], $match)) {
32
$uploader->setExtension($match[1]);
33
}
34
}
35
36
/**
37
* {@inheritdoc}
38
*/
39
public static function save($original, $destination)
40
{
41
$fileData = explode(';base64,', $original, 2);
42
43
if (!@file_put_contents($destination, base64_decode($fileData[1]))) {
44
throw new \RuntimeException("Unable to copy base64 to '{$destination}'");
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: