Strict standards: only variables should be passed by reference - php error

    $file_name = $_FILES['profile_image']['name'];
    $file_ext = end(explode('.', $file_name)); //line 10
    $file_ext = strtolower($file_ext);
    $file_temp = $_FILES['profile_image']['tmp_name'];

Strict standards: only variables should be passed by reference on line 10

How to get rid of this error? Please thanks:)

+5
source share
3 answers

end() expects that its parameter can be passed by reference, and only variables can be passed by reference:

$array = explode('.', $file_name);
$file_ext = end( $array); 

You can fix this, first store the array in a variable and then call end().

+14
source

If you need the last element of the array, do the following:

$arr = explode(".", $file_name);
$file_ext = $arr[count($arr) - 1];

If you are trying to just get the extension from a file, use

$ext = pathinfo($file_name, PATHINFO_EXTENSION);
0
source

Actually, if you write $ ext = end (explode ('.', $ Filename)); to get the file extension, then "Only variables should be passed by reference" can be displayed in php. For this reason, try using two steps, for example: $ tmp = explode ('.', $ Filename); $ ext = end ($ tmp);

0
source

All Articles