5
    $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 :)

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
  • possible duplicate of [Strict Standards: Only variables should be passed by reference](http://stackoverflow.com/questions/2354609/strict-standards-only-variables-should-be-passed-by-reference) – Lorenz Meyer Jun 21 '14 at 08:23
  • Possible duplicate of [Only variables should be passed by reference](https://stackoverflow.com/q/4636166/1255289) – miken32 Oct 11 '17 at 21:59

3 Answers3

15

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().

nickb
  • 59,313
  • 13
  • 108
  • 143
0

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);
Matt
  • 6,993
  • 4
  • 29
  • 50
0

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

lmnmamun
  • 1
  • 1