Only variables should be passed by reference

后端 未结 12 1445
囚心锁ツ
囚心锁ツ 2020-11-22 06:14
// Other variables
$MAX_FILENAME_LENGTH = 260;
$file_name = $_FILES[$upload_name][\'name\'];
//echo \"testing-\".$file_name.\"
\"; //$file_name = strtolower
相关标签:
12条回答
  • 2020-11-22 06:15

    end(...[explode('.', $file_name)]) has worked since PHP 5.6. This is documented in the RFC although not in PHP docs themselves.

    0 讨论(0)
  • 2020-11-22 06:17

    Php 7 compatible proper usage:

    $fileName      = 'long.file.name.jpg';
    $tmp           = explode('.', $fileName);
    $fileExtension = end($tmp);
    
    echo $fileExtension;
    // jpg
    
    0 讨论(0)
  • 2020-11-22 06:19

    $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..

    0 讨论(0)
  • 2020-11-22 06:22

    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 .

    0 讨论(0)
  • 2020-11-22 06:27

    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.

    0 讨论(0)
  • 2020-11-22 06:30

    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.

    0 讨论(0)
提交回复
热议问题