我在 PHP 中有一个文件上传脚本。该脚本适用于较小的文件(小于 2MB),但需要使用此脚本上传的较大文件(约 20MB)无法上传。
脚本如下,然后是更多解释:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$file = $_FILES["uploaddistance"]["name"];
$fileTmpLoc = $_FILES["uploaddistance"]["tmp_name"];
$pathlevel3 = 'distance/level3/';
$pathlevel4 = 'distance/level4/';
$pathlevel5 = 'distance/level5/';
$pathlevel6 = 'distance/level6/';
$level = $_POST['distancecourse'];
$module = $_POST['distancemodule'];
$kaboom = explode(".", $file);
$extension = end($kaboom);
if ($level == "level3"){
$pathandname = $pathlevel3 . $module . '.' . $extension;
if (file_exists($pathandname)){
unlink($pathandname);
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
else {
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
}
else if ($level == "level4"){
$pathandname = $pathlevel4 . $module . '.' . $extension;
if (file_exists($pathandname)){
unlink($pathandname);
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
else {
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
}
else if ($level == "level5"){
$pathandname = $pathlevel5 . $module . '.' . $extension;
if (file_exists($pathandname)){
unlink($pathandname);
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
else {
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
}
else if ($level == "level6"){
$pathandname = $pathlevel6 . $module . '.' . $extension;
if (file_exists($pathandname)){
unlink($pathandname);
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
else {
$moveresult = move_uploaded_file($fileTmpLoc, $pathandname);
if ($moveresult == true){
echo "Workbook uploaded";
}
}
}
else {
echo "Error 1";
echo $level;
echo $module;
}
}
else {
echo "error 2";
}
?>
当我上传较大的文件时,会出现“错误 1”消息,表明没有任何 POST 值被传递给脚本。就像我说的,上传较小的文件时情况并非如此。
我尝试创建自定义 php.ini 文件并更改最大文件大小。我进行了以下更改:
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 96M
php.ini 文件位于我的主目录 (public_html) 中。据我了解,目录中的任何脚本都应该自动使用它。当我在站点上运行phpinfo()
测试时,它说加载的配置文件是 public_html/php.ini (有关详细信息,请参见http://www.xenonacademy.org.uk/phptest.php),这表明配置文件是正确,但由于某种原因,问题仍然存在。
另外,在运行这个测试时,它显示memory_limit
只有 64M,而不是我在 php.ini 中指定的 96,但是upload_max_filesize
andpost_max_size
是正确的。如果这些设置正确,为什么这不起作用?我需要include()
在相关脚本中使用我的 php.ini,还是这里有更复杂的工作?
谁能解释我哪里出错了?
谢谢!