只应通过引用传递变量。

只应通过引用传递变量。

// 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');

有什么想法吗?两天后仍然卡住。


慕哥6287543
浏览 392回答 3
3回答

莫回无

分配结果explode传递给一个变量,并将该变量传递给end:$tmp&nbsp;=&nbsp;explode('.',&nbsp;$file_name);$file_extension&nbsp;=&nbsp;end($tmp);问题是,end需要引用,因为它修改了数组的内部表示(即,它使当前元素指针指向最后一个元素)。结果explode('.', $file_name)不能转换为引用。这是PHP语言中的一个限制,可能是出于简单的原因而存在的。

眼眸繁星

PHP 7兼容的正确用法:$fileName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;'long.file.name.jpg';$tmp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;explode('.',&nbsp;$fileName);$fileExtension&nbsp;=&nbsp;end($tmp);echo&nbsp;$fileExtension;//&nbsp;jpg

潇湘沐

其他人都已经告诉了你出错的原因,但以下是您想做的最好的方法:$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
打开App,查看更多内容
随时随地看视频慕课网APP