// Other variables
$MAX_FILENAME_LENGTH = 260;
$file_name = $_FILES[$upload_name][\'name\'];
//echo \"testing-\".$file_name.\"
\";
//$file_name = strtolower
end(...[explode('.', $file_name)])
has worked since PHP 5.6. This is documented in the RFC although not in PHP docs themselves.
Php 7 compatible proper usage:
$fileName = 'long.file.name.jpg';
$tmp = explode('.', $fileName);
$fileExtension = end($tmp);
echo $fileExtension;
// jpg
$file_extension = end(explode('.', $file_name)); //ERROR ON THIS LINE
change this line as,
$file_extension = end((explode('.', $file_name))); //no errors
Technique is simple please put one more brackets for explode,
(explode()), then only it can perform independently..
save the array from explode() to a variable, and then call end() on this variable:
$tmp = explode('.', $file_name);
$file_extension = end($tmp);
btw: I use this code to get the file extension:
$ext = substr( strrchr($file_name, '.'), 1);
where strrchr
extracts the string after the last .
and substr
cuts off the .
Try this:
$parts = explode('.', $file_name);
$file_extension = end($parts);
The reason is that the argument for end
is passed by reference, since end
modifies the array by advancing its internal pointer to the final element. If you're not passing a variable in, there's nothing for a reference to point to.
See end in the PHP manual for more info.
First, you will have to store the value in a variable like this
$value = explode("/", $string);
Then you can use the end function to get the last index from an array like this
echo end($value);
I hope it will work for you.