0

我真的不太了解PHP。但无论如何,我无法使用以下 php 上传 .csv 文件。该文件小于 5MB。这是怎么回事?总共有 79,500 行记录,只有四列和简单的值,如下所示:

27589   16990   161.7000095 0.838494
27589   17067   161.7000095 0.838494
27820   17144   315.7000095 0.859458
27820   17221   315.7000095 0.859458
27820   17606   315.7000095 0.866033
27820   17683   315.7000095 0.866033

我对文件进行了剖析,上传了多达 6 万行数据并被炸掉了,也就是 1.93MB。除此之外的任何事情都行不通。错误代码为“ -- CSV file to load: failure to upload the file >>> Error code: 1
” 错误代码 1。

另外,我如何打印完整的 PHP 错误消息,而不仅仅是我不确定它对应的值“1”?即...输出打印像这样“UPLOAD_ERR_INI_SIZE: 1”?

<?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");
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);

//commented out for “Only variables should be passed by reference” error
//$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"]);
        }       
}

?>

这是其他用户为正确捕获错误而添加的行。请让我知道这是否正确对不起我根本不了解 PHP。无论如何,打印的错误只是“-- CSV file to load: failure to upload the file >>> Error code: 1

<?php
// using upload at click from http://code.google.com/p/upload-at-click/
// FileData is the name for the input file

ini_set('display_errors', 1); error_reporting(E_ALL);

$file_result = "";
$file = $_FILES['Filedata'];

$allowedExtensions = array("csv", "txt");
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);
4

2 回答 2

4
  1. 设置你的upload_max_filesize东西高于 2M
  2. 你的post_max_size应该高于2M
  3. 确保max_execution_time足够高
  4. memory_limit也应该足够高,但应该是 16M 应该没问题。
  5. 确保set_time_limit()足够高
于 2012-08-16T00:15:49.550 回答
1

只需增加 php.ini 文件中的上传大小:

于 2012-08-16T00:15:25.840 回答