我无法真正阅读PHP,但我试图通过php在我的页面上传一个csv文件,并得到以下错误。我知道有许多线索谈论这个,但我不太明白他们的意思。如果有人可以向我解释发生了什么并提供解决方案,那就寻找答案。
严格标准:只应通过引用传递变量 在 C:\ xampp \ htdocs \ search \ php \ loader \ csvFileUploader1.php 上 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"]);
}
}
?>
答案 0 :(得分:4)
您无法将函数的返回值传递给end()
。
成功:
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);
你会遇到与其他PHP函数相同的问题。例如,empty(someFunction())
无效。