Praba Praba - 7 months ago 11
PHP Question

Why get this notice in PHP


Notice: Only variables should be passed by reference in
C:\xampp\htdocs\PHP\processor.php on line 43

Line 43 is: $extension = end(explode(".",
strtolower($_FILES['photoUpload']['name'])));


$allowedExts = array( "gif", "jpeg", "jpg", "png" );
$extension = end(explode(".", strtolower($_FILES['photoUpload']['name'])));

$allowedType = array( "image/gif", "image/jpeg", "image/jpg", "image/png" );

if( !in_array($_FILES['photoUpload']['type'], $allowedType) )
die ("<br>Unsupported file type!");

if( !in_array($extension, $allowedExts) )
die ("<br>Unsupported file extension!");

Answer

You need to assign the value of explode() to a variable before passing it to end:

$explode = explode(".", strtolower($_FILES['photoUpload']['name']));
$extension = end($explode);

This is because end needs to have a reference and the result of explode() cannot be used as a reference.

end — Set the internal pointer of an array to its last element

More information at http://php.net/manual/en/function.end.php.