我真的不太了解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
我解剖了这个文件并上传了多达60,000行数据并被轰炸,这是1.93MB。除此之外的任何事情都行不通。错误代码为“ - 要加载的CSV文件:无法上传文件>>>错误代码:1
”错误代码1.
另外,如何打印完整的PHP错误消息而不仅仅是值“1”,我不确定它对应的是什么? ie ...输出打印如下“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"]);
}
}
&GT;
这是由其他用户建议添加的行以正确捕获错误。请告诉我,如果对不起,我根本不懂PHP。无论如何,打印的错误只是“ - 要加载的CSV文件:无法上传文件&gt;&gt;&gt;错误代码: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);
答案 0 :(得分:4)
upload_max_filesize
某事设置为高于2M post_max_size
应高于2M max_execution_time
足够高memory_limit
也应该足够高,但它应该是16M,应该没问题。set_time_limit()
足够高答案 1 :(得分:1)
只需增加php.ini文件中的上传大小: