只有变量应该通过引用传递 [英] Only variables should be passed by reference
本文介绍了只有变量应该通过引用传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// 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'
);
有什么想法吗?2天后仍然卡住.
Any ideas? After 2 days still stuck.
推荐答案
将explode
的结果赋值给一个变量,并将该变量传递给end
:
Assign the result of explode
to a variable and pass that variable to end
:
$tmp = explode('.', $file_name);
$file_extension = end($tmp);
问题是,end
需要一个引用,因为它修改了数组的内部表示(即它使当前元素指针指向最后一个元素).
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).
explode('.', $file_name)
的结果不能转化为引用.这是 PHP 语言中的一个限制,可能出于简单原因而存在.
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.
这篇关于只有变量应该通过引用传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文