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...
Why not use pathinfo (PHP >= 4.0.3
), i.e.:
$ext = pathinfo($_FILES["rfile"]["name"])['extension'];
Live PHP demo
Your localhost is on an old PHP version or is not configured to display strict standards errors.
Now in PHP, you should do:
$explode = explode(".", $_FILES["rfile"]["name"]);
$extension = end($explode);
See the example in the doc: http://php.net/manual/en/function.end.php#refsect1-function.end-examples
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);