简体   繁体   English

严格标准:只应通过引用传递变量 - php错误

[英]Strict Standards: Only variables should be passed by reference - php error

    $file_name = $_FILES['profile_image']['name'];
    $file_ext = end(explode('.', $file_name)); //line 10
    $file_ext = strtolower($file_ext);
    $file_temp = $_FILES['profile_image']['tmp_name'];

Strict Standards: Only variables should be passed by reference in on line 10 严格标准:在第10行只能通过引用传递变量

How do I get rid of this error? 我该如何摆脱这个错误? Please and thank you :) 谢谢,麻烦您了 :)

end() expects its parameter to be able to be passed by reference, and only variables can be passed by reference: end()期望它的参数能够通过引用传递,并且只能通过引用传递变量:

$array = explode('.', $file_name);
$file_ext = end( $array); 

You can fix this by saving the array to a variable first, then calling end() . 您可以通过先将数组保存到变量,然后调用end()来解决此问题。

If you want the last item in the array, do this: 如果您想要数组中的最后一项,请执行以下操作:

$arr = explode(".", $file_name);
$file_ext = $arr[count($arr) - 1];

If you're trying to just get the extension from the file, use 如果您尝试从文件中获取扩展名,请使用

$ext = pathinfo($file_name, PATHINFO_EXTENSION);

Actually, if you write $ext = end(explode('.', $filename)); 实际上,如果你写$ ext = end(explode('。',$ filename)); for getting the file extension then "Only variables should be passed by reference" can be show in php. 获取文件扩展名然后“只能通过引用传递变量”可以在php中显示。 For this reason, try to use it two steps, like: $tmp = explode('.', $filename); 出于这个原因,尝试使用它两个步骤,例如:$ tmp = explode('。',$ filename); $ext = end($tmp); $ ext = end($ tmp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 烦人的PHP错误:“严格的标准:只有变量应该通过引用传递” - Annoying PHP error: “Strict Standards: Only variables should be passed by reference in” 严格标准:只应在functions.php中通过引用传递变量 - Strict Standards: Only variables should be passed by reference in functions.php PHP严格标准:在wordpress函数中,只能通过引用传递变量 - PHP Strict Standards: Only variables should be passed by reference in on wordpress function 严格的标准:只能通过引用传递变量PHP购物车 - Strict Standards: Only variables should be passed by reference PHP Shopping Cart PHP 严格标准:在 .lib 中只应通过引用传递变量 - PHP Strict Standards: Only variables should be passed by reference in .lib PHP严格标准:只有变量应通过引用传递给 - PHP Strict Standards: Only variables should be passed by reference in 面向PHP对象的“严格标准:仅变量应通过引用传递给” - PHP Object Oriented “Strict standards: Only variables should be passed by reference in” 严格标准:只有变量应通过引用传递给 - Strict Standards: Only variables should be passed by reference in 严格的标准:只有变量应该通过引用传递 - Strict Standards: Only variables should be passed by reference 严格标准:仅变量应通过引用传递 - Strict Standards: Only variables should be passed by reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM