我真的不太了解PHP。但无论如何,我无法使用以下 php 上传 .csv 文件。我已经解决了与 upload_max 大小相关的属性的问题。在我的本地运行良好,但在沙箱上运行良好。是文件类型问题吗?
我只能让它打印这样的东西......这根本没有帮助。“--要加载的 CSV 文件:>>> 不是有效的文件: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 文件:>>> 不是有效的文件: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);