我真的看不懂PHP,但我正在尝试通过php在我的页面中上传csv文件,并得到以下错误。我知道有很多线程在谈论这个,但我不太明白它们是什么意思。如果有人可以向我解释发生了什么并提供解决方案,请寻找答案。
严格的标准:只有变量应该通过引用传递 in C:''xampp''htdocs''search''php''loader''csvFileUploader1.php on 第 9 行上传
文件失败>>> 错误代码:
1
这是 PHP
<?php
// using upload at click from http://code.google.com/p/upload-at-click/
// FileData is the name for the input file
$file_result = "";
$file = $_FILES['Filedata'];
$allowedExtensions = array("csv", "txt");
$extension = end(explode(".", $file["name"]));
function isAllowedExtension($fileName) {
global $allowedExtensions;
return in_array(end(explode(".", $fileName)), $allowedExtensions);
}
if($file["error"] > 0){
echo "failure to upload the file >>> ". "Error code: ".$file["error"]."<br>";
}else{
//echo " >>> CURRENT DIR: ".getcwd() . "'n";
$workDir = getcwd();
$dir = substr($workDir, 0, -10);
$path = $file["name"];
$newFileLoc = $dir.$path;
$file_result.=
"<br> Upload: " . $file["name"] . "<br>" .
" Type: " . $file["type"] . "<br>" .
" Size: " . $file["size"] . "<br>" .
" file uploaded to: ".$newFileLoc."<br>";
// txt - text/plain
// rtf - application/msword
// dat/obj - application/octet-stream
// csv - application/vnd.ms-excel
// maximum 200 MB file - 200,000,000 k
if ( ($file["type"] == "application/vnd.ms-excel" || $file["type"] == "text/plain")
&& isAllowedExtension($file["name"])
&& ($file["size"] < 200000000)
)
{
move_uploaded_file($file["tmp_name"], $newFileLoc);
//echo $file_result.=" >>> File uploaded successfull!!";
echo "|".$path;//"filePath : " . $newFileLoc;
}else{
echo " >>> NOT a file valid: ". isAllowedExtension($file["name"]);
}
}
?>
不能将函数的返回值传递给end()
。
来得及:
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);
使用其他 PHP 函数时,您也会遇到同样的问题。例如,empty(someFunction())
将不起作用。