0

我无法真正阅读 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"]);
        }       
}


?>
4

1 回答 1

4

您不能将函数的返回值传递给end().

做了:

$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);

其他 PHP 函数也会有同样的问题。例如empty(someFunction())不会工作。

于 2012-08-15T22:07:27.373 回答