Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

end(explode) Strict Standards: Only variables should be passed by reference in

Tags:

php

explode

I have this code to get the extension of a file:

$extension = end(explode(".", $_FILES["rfile"]["name"]));

That is working fine on localhost, but when I upload online hosting, it is giving me this error:

Strict Standards: Only variables should be passed by reference in...

like image 901
Elyor Avatar asked Dec 03 '22 16:12

Elyor


2 Answers

Why not use pathinfo (PHP >= 4.0.3), i.e.:

$ext = pathinfo($_FILES["rfile"]["name"])['extension'];

Live PHP demo

http://ideone.com/eMpbnL

like image 196
Pedro Lobito Avatar answered Dec 06 '22 10:12

Pedro Lobito


PHP end takes an reference to a variable as argument. http://php.net/manual/en/function.end.php

So, with strict standards enabled, you should put the result of explode into a variable first:

$exp = explode(".", $_FILES["rfile"]["name"])
$extension = end($exp);
like image 32
dognose Avatar answered Dec 06 '22 11:12

dognose