[PHP] Onlyvariablesshouldbepassedbyreference
A php Error was encountered Severity: Runtime Notice Message: Only variables shocould be passed by reference $ file_name = $ _ FILES [$ upload_name] ['name']; $ file_extension = end (explode ('. ', $ file_name); // error on this line cause: when getting the suffix, use the end function to point the internal pointer of the array to the last element, while the end function is used to reference the passed value. The problem is, that end requires a reference, because it modifies the internal representation of the array (I. e. it makes the current element pointer point to the last element ). the result of explode ('. ', $ file_name) cannot be turned into a reference. this is a restriction in the PHP language, that probably exists for simplicity reasons. the array. this array is passed by reference because it is mo Dified by the function. this means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference. solution: (1) define a variable to obtain the value after explode, and then use the end function: $ parts = explode ('. ', $ file_name); $ file_extension = end ($ parts); (2) use the substr and strrchr functions to retrieve the file suffix: $ ext = substr (strrchr ($ file_name ,'. '), 1); (3) use the pathinfo function to get the file suffix: $ file_ext = pathinfo ($ file_name, PATHINFO_EXTENSION); end () function points the internal pointer of the array to the last element, and returns the value of this element (if successful ). The pathinfo () function returns the file path information in an array. Reference link: http://www.w3school.com.cn/php/func_array_end.asp http://www.w3school.com.cn/php/func_filesystem_pathinfo.asp http://stackoverflow.com/questions/4636166/only-variables-should-be-passed-by-reference