0

我正在制作一个文件上传系统。用户使用动态下拉列表选择上传位置。这就是我现在面临的问题。这是我的表格。

<form action="uploader.php" method="POST" enctype="multipart/form-data" name="uploads">

            <label for="file">Choose a file: </label> 

                <input type="file" name="userfile" id="userfile"><br/><br/>

                    <select id="text-one" name="one"> 

                        <option selected value="base">Select Department</option>
                        <option value="CSE" name="cse">Computer Science Engineering</option>
                        <option value="ECE" name="ece">Electronics & Communication Engineering</option>
                        <option value="MECH" name="mech">Mechanical Engineering</option>

                    </select>

                    <br /><br/>

                    <select id="text-two" name="two">
                        <option>Select Semester</option>
                    </select>

                    <br /><br/>

                    <select id="text-three" name="three">
                        <option>Select Subject</option>
                    </select>

                    <br/><br/>

            <button class ="btn btn-primary" button type="submit" name="upload" value="Upload" onClick="val()">Upload</button>

        </form>

这是我链接到的另一个 php 文件。

<?php
if(isset($_POST['upload']))
{ 
  $path1=$_POST['one']."/"; 
  $path2=$_POST['two']."/"; 
  $path3=$_POST['three']."/";   
  $upload_path=$path1.$path2.$path3;
 }
else
 {
  echo "Select a Subject";
  echo "<br>";
}
$allowed_filetypes = array('.doc','.docx','.jpg','.jpeg','.png','.ppt','.pptx','.xls','.xlsx','.pdf','.txt','.zip','.rar'); 
$max_filesize = 20000000; 
$filename = $_FILES['userfile']['name']; 
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
  die("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('You cannot upload the following type of file!')
        window.location.href='upload.php';
     </SCRIPT>");
if(filesize($_FILES['userfile']['size']) > $max_filesize)
  die("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('The file you attempted to upload is too large!')
        window.location.href='upload.php';
     </SCRIPT>");
if(!is_writable($upload_path))
  die("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('You cannot upload to the specified directory!')
        window.location.href='upload.php';
     </SCRIPT>");
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
  echo ("<SCRIPT LANGUAGE='JavaScript'>
          window.alert('Your file has been uploaded successfully')
          window.location.href='upload.php';
        </SCRIPT>");
else
  echo ("<SCRIPT LANGUAGE='JavaScript'>
          window.alert('There was an error during the file upload!')
          window.location.href='upload.php';
        </SCRIPT>");
?>

我已经使用以下设置编辑了 phpini 文件,并且还在 php 文件夹中创建了一个 .htaccess 文件。

upload_max_filesize 25M post_max_size 25M memory_limit 64M

但是当我故意上传一个大于 25 MB 的文件时,我得到了标题中给出的错误。此外,考虑到违反了最大文件大小,它不会给出与文件大小相关的错误,即您尝试上传的文件太大,它说您无法上传以下类型的文件。在后台发布长度警告的事情来了。

请帮我解决一下这个。我在我的本地主机上。

4

1 回答 1

1

post_max_size 表示所有文件大小的总和 + 其他帖子字段。
post_max_size 应始终大于 upload_max_filesize

尝试将 post_max_size 设置为 26M

补充:首先检查是否设置了 $_FILES['userfile'] 即:

if(!isset($_FILES['userfile'])) 
  die("<SCRIPT LANGUAGE='JavaScript'> 
       window.alert('No file upload !');
       window.location.href='upload.php'; 
      </SCRIPT>");
于 2012-11-29T16:46:30.830 回答