Only variables should be passed by reference

2018-12-31 07:46发布

// Other variables
$MAX_FILENAME_LENGTH = 260;
$file_name = $_FILES[$upload_name]['name'];
//echo "testing-".$file_name."<br>";
//$file_name = strtolower($file_name);
$file_extension = end(explode('.', $file_name)); //ERROR ON THIS LINE
$uploadErrors = array(
    0=>'There is no error, the file uploaded with success',
    1=>'The uploaded file exceeds the upload max filesize allowed.',
    2=>'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
    3=>'The uploaded file was only partially uploaded',
    4=>'No file was uploaded',
    6=>'Missing a temporary folder'
);

Any ideas? After 2 days still stuck.

标签: php
9条回答
路过你的时光
2楼-- · 2018-12-31 08:11

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

查看更多
闭嘴吧你
3楼-- · 2018-12-31 08:14

Everyone else has already given you the reason you're getting an error, but here's the best way to do what you want to do: $file_extension = pathinfo($file_name, PATHINFO_EXTENSION);

查看更多
查无此人
4楼-- · 2018-12-31 08:14

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 .

查看更多
登录 后发表回答