-1

I am currently trying File Upload on PHP with security but I have this warning:

Strict standards: Only variables should be passed by reference

I was able to get the file name with this:

$file_name = $_FILES['image']['name'];

This is the line that the warning indicates:

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

This line is to get the file extension of the uploaded file. Would you please help me fix this line? I will totally appreciate your help!

The file I used for testing is named "A.jpg"

D. Gatch
  • 167
  • 4
  • 13

1 Answers1

0

Alternatively, you can get file extension in this way:

<?php
$file_name = 'test_file_uploaded.abc.txt';
$file_ext = strtolower(substr($file_name, (strrpos($file_name, '.') + 1), strlen($file_name)));

echo $file_name; // output "test_file_uploaded.abc.txt"
echo $file_ext;  // output "txt"
?>
d.coder
  • 1,988
  • 16
  • 23