2014-09-22 79 views
1

我遇到文件上傳問題,它沒有上傳。當上傳7mb視頻時,$ _FILES ['video'] ['tmp_name']爲空,當我上傳15mb文件時,表單實際上並沒有「提交」,只是刷新了。PHP文件上傳不提交

這裏是我的代碼來處理提交:

if(isset($_POST['submit'])){ 

    $blah = "".$_FILES['video']['size'].""; 
    var_dump($blah); 

    if(empty($_FILES['video']) && empty($_POST['create_video'])){ 
     echo "<div class='alert alert-danger' role='alert'><center><strong>Missing Fields:</strong> Please choose a video or request the ##### team create a video.</center></div>"; 
    } else { 

     if(empty($_FILES['video']['name']) && $_POST['create_video'] == "true"){ 
      $_SESSION['create_video'] = protect($_POST['create_video']); 
      ?> 
       <script type="text/javascript"> 
        window.location = "NEXT_PAGE"; 
       </script> 
      <? 

       exit(); 

     }else{ 

      //if all were filled in continue 
      $allowedExts = array("mp4", "MP4", "m4a"); 
      $extension = pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION); 

      if (($_FILES["video"]["size"] <= 15728640) && (in_array($extension, $allowedExts))) { 

       if ($_FILES["video"]["error"] > 0){ 
        echo "Return Code: " . $_FILES["video"]["error"] . "<br />"; 
       }else{ 
        //Get the height and width of our video 
        //$getID3 = new getID3; 
        //$file = $getID3->analyze($_FILES["video"]["tmp_name"]); 
        //$width =$file['video']['resolution_x']; 
        //$height = $file['video']['resolution_y']; 
        $img = getimagesize($_FILES['video']['tmp_name']); 
        $width = $img[0]; 
        $height = $img[1]; 
        var_dump($width); var_dump($height); 
        if(($height < 719) || ($width < 1279)){ 
         echo "<div class='alert alert-danger' role='alert'><center><strong>Invalid file dimensions</strong> Please ensure your image is the correct size.</center></div>"; 

        } else { 

         $ext = findexts ($_FILES["video"]["name"]); 
         $ran = rand(); 
         $file_name = $_FILES["video"]["name"] = "".$_SESSION['uid'] ."".$ran.".".$ext.""; 

          if (file_exists("uploads/video_ads/".$_SESSION['uid']."_" . $_FILES["video"]["name"])){ 
           echo $_FILES["video"]["name"] . " already exists. "; 
          }else{ 
           move_uploaded_file($_FILES["video"]["tmp_name"], 
           "uploads/video_ads/".$_SESSION['uid']."_" . $_FILES["video"]["name"]); 

          //Save the link of our ad 
          $_SESSION['video'] = "####/uploads/video_ads/".$_SESSION['uid']."_" . $_FILES["video"]["name"].""; 
          $_SESSION['create_video'] = protect($_POST['create_video']); 

          ?> 
           <script type="text/javascript"> 
            window.location = "NEXT_PAGE"; 
           </script> 
          <? 
          exit(); 

          } 
        } 
       } 
      } else { 
       echo "<div class='alert alert-danger' role='alert'><center><strong>Invalid file type</strong> Please upload a video in MP4 format.</center></div>"; 
      } 
     } 
    } 
} 

這裏是我的實際形式:

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" class="form-signin" role="form" enctype="multipart/form-data"> 
        <br /> 
        <input type="file" name="video" id="video" /><br /> 
        <br /> 


        <div class="row"> 
         <div class="col-md-12"> 
          <strong class="ad-header" 
           style="font-size: 150%; font-weight: bold;">Quick Tips:</strong> 
         </div> 

        </div> 
        <hr> 
        <h3 class="ad-sub-header" style="color: #559fd3; font-size: 150%;">Need 
         help to create engaging artwork for your brand?</h3> 
        <strong class="ad-header" style="font-size: 100%;">#### 
         has the creative team to get it done for you</strong><br /> Only ##/hr - 
        3 revisions - Artwork is yours to keep. <br /> 
        <br /> <input type="checkbox" name="create_video" value="true" /> 
        I don't have an ad. Please create one. <br /> 
        <br /> <input class="btn btn-lg btn-primary btn-block" 
         type="submit" name="submit" value="Continue To Step 5" /> 
       </form> 
+0

-1代碼亂碼。缺少echo:'<?php echo $ _SERVER ['PHP_SELF']; ?>'或'<?= $ _SERVER ['PHP_SELF']; ?>' – DanFromGermany 2014-09-22 14:50:54

+0

我繼續並添加了回聲。問題依然存在。 – user1890328 2014-09-22 16:17:35

回答

2

賠率是您的服務器不接受上傳超過2M的尺寸更大。您需要檢查phpinfo()(或者如果您有權訪問它,請訪問php.ini)以查看您當前的限制。如果它只有2M或小於上傳大小,則需要對其進行編輯以允許更大的上傳。如果你在共享主機上,你可能會運氣不好。

+0

問候,我自己的服務器和設置(每cPanel upload_max_filesize:50M和所有執行時間是300) – user1890328 2014-09-22 14:32:59

+0

什麼是內存限制? – 2014-09-22 14:34:31

+0

內存限制爲-1(無限制) – user1890328 2014-09-22 14:42:15

0

嘗試用此設置調整你的php.ini:

php_value memory_limit 96M 
php_value post_max_size 96M 
php_value upload_max_filesize 96M 

,並確保file_uploads設置是On

+0

我把這個添加到了php.ini中,並且雙重檢查了file_uploads已經啓動了。問題依然存在。 – user1890328 2014-09-22 16:17:55

0

對於任何人誰都有這個問題。我不得不增加我默認設置爲8M的post_max_size。