5
votes
    $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 in on line 10

How do I get rid of this error? Please and thank you :)

3

3 Answers

15
votes

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

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

You can fix this by saving the array to a variable first, then calling end().

0
votes

If you want the last item in the array, do this:

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

If you're trying to just get the extension from the file, use

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

Actually, if you write $ext = end(explode('.', $filename)); for getting the file extension then "Only variables should be passed by reference" can be show in php. For this reason, try to use it two steps, like: $tmp = explode('.', $filename); $ext = end($tmp);