文件未上传到地图

时间:2015-10-07 07:54:39

标签: php html file-upload

这是我的HTML代码:

<form action="producttoevoegen.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
                            <label for="Upload"></label>
                            <input type="file" name="Upload[]" multiple="multiple" id="Upload" />
                            <input type="submit" name="UploadButton" id="UploadButton" value="Upload" />
                          </form>

这是我的PHP代码:

                    <?php
                            if(isset($_FILES['Upload'])){

                              $UploadName = $_FILES['Upload']['name'];
                              $UploadType = $_FILES['Upload']['type'];
                              $FileSize = $_FILES['Upload']['size'];

                              $UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);

                              if(($FileSize > 125000)){

                                die("Error - File too Big");

                              }

                                for($i=0; $i<count($UploadName); $i++) {
                                $tmpFilePath = $_FILES['Upload']['tmp_name'][$i];

                                if ($tmpFilePath != ""){
                                  $newFilePath = /upload/" .  $UploadName[$i];

                                  if(move_uploaded_file($tmpFilePath, $newFilePath)) {
                            }
                              }
                             }
                            }

当我尝试上传文件时,它不起作用。它没有显示在地图中。我尝试了很多东西,但没有任何效果。有没有人看到我犯的错误?在此先感谢!!

2 个答案:

答案 0 :(得分:1)

if(isset($_FILES['Upload'])){

    for($i=0; $i<count($UploadName); $i++) {

     $UploadName = $_FILES['Upload']['name'][$i];
     $UploadType = $_FILES['Upload']['type'][$i]; 
     $FileSize = $_FILES['Upload']['size'][$i]; 

     $UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);

     if(($FileSize > 125000)){
        die("Error - File too Big");
     }      
     $tmpFilePath = $_FILES['Upload']['tmp_name'][$i];
     if ($tmpFilePath != "") {
      $newFilePath = "/upload/" .  $UploadName[$i]; 
          if(move_uploaded_file($tmpFilePath, $newFilePath)) {
          }
      }
     }
}

答案 1 :(得分:0)

请查找更新的代码

<form action="producttoevoegen.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
                            <label for="Upload"></label>
                            <input type="file" name="Upload" multiple="multiple" id="Upload" />
                            <input type="submit" name="UploadButton" id="UploadButton" value="Upload" />
                          </form>

将此代码用于由@Minesh Patel提供的PHP脚本

if(isset($_FILES['Upload'])){

    for($i=0; $i<count($UploadName); $i++) {

     $UploadName = $_FILES['Upload']['name'][$i];
     $UploadType = $_FILES['Upload']['type'][$i]; 
     $FileSize = $_FILES['Upload']['size'][$i]; 

     $UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);

     if(($FileSize > 125000)){
        die("Error - File too Big");
     }      
     $tmpFilePath = $_FILES['Upload']['tmp_name'][$i];
     if ($tmpFilePath != "") {
      $newFilePath = "/upload/" .  $UploadName[$i]; 
          if(move_uploaded_file($tmpFilePath, $newFilePath)) {
          }
      }
     }
}