Praba
Praba

Reputation: 67

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!");

Upvotes: 0

Views: 48

Answers (2)

Shuhad zaman
Shuhad zaman

Reputation: 3390

You can also use following method to get extension

$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);

Upvotes: 0

Panda
Panda

Reputation: 6896

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.

Upvotes: 1

Related Questions