我有一个处理文件上传的脚本。我上传了小于 1 MB 的文件,但是当文件超过 1 MB 时,脚本似乎将临时文件路径设置为 null。下面是脚本:
$total = count($_FILES['DocName']['tmp_name']);
for($i = 0; $i < $total; $i++) {
// Get the temp file path
$tmpFilePath = $_FILES['DocName']['tmp_name'][$i];
// Check if we have a path
if ($tmpFilePath != "") {
// Variables from form
$FolderName = $_POST['FolderName'];
$FolderName = stripslashes($FolderName);
$FolderName = mysql_real_escape_string($FolderName);
//Setup our new file path
// Check if folder name is home, if so, set the file path to that folder
if ($FolderName == "Home") {
$target_dir = "../../cdn.brmbc.com/usercontent/".$UserID."/";
}
// If the folder name is not home, make the file go to that folder
else {
$IsInFolder = 1;
$target_dir = "../../cdn.brmbc.com/usercontent/".$UserID."/".$FolderName."/";
}
$target_file = $target_dir . basename($_FILES["DocName"]["name"][$i]);
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
$DocumentName = $_FILES["DocName"]["name"][$i];
echo $tmpFilePath . "<br>";
echo $target_file . "<br>";
echo $FileType . "<br>";
echo $DocumentName . "<br>";
}
// Go home if there is no temp path
else {
echo $tmpFilePath . "<br>" . "Failed to upload";
}
}
代码似乎有什么不正确的地方,或者这只是服务器问题?
如果您的上传适用于 1MB 以下的文件,我猜这是一个 php.ini 设置。
如果你可以访问你的php.ini搜索一个名为"max_file_uploads"的设置 - 我敢打赌它设置为1MB。
http://php.net/upload-max-filesize
我认为你必须更改php.ini文件。在php.ini文件中你会发现
upload_max_filesize=2M
像这样的东西。在那里,您必须增加文件大小。我认为你的就像
upload_max_filesize=1M
增加文件大小后,它应该是okey。