【问题标题】:PHP File Upload Not SubmittingPHP文件上传未提交
【发布时间】:2014-11-16 13:15:01
【问题描述】:

我在无法上传的文件上传时遇到问题。上传 7mb 视频时,$_FILES['video']['tmp_name'] 是空的,而当我上传 15mb 文件时,表单实际上并没有“提交”,只是刷新。

这是我处理提交的代码:

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>

【问题讨论】:

  • -1 表示这乱七八糟的代码。缺少回显:&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;&lt;?= $_SERVER['PHP_SELF']; ?&gt;
  • 我继续添加回声。问题仍然存在。

标签: php file-upload php-5.4


【解决方案1】:

您的服务器可能不接受大小超过 2M 的上传。您需要检查phpinfo()(或 php.ini,如果您可以访问它)来查看您当前的限制是多少。如果它只有 2M 或小于您的上传大小,您需要对其进行编辑以允许更大的上传。如果您使用的是共享主机,您可能会不走运。

【讨论】:

  • 您好,我拥有服务器和设置(每个 cPanel 是 upload_max_filesize: 50M 并且所有执行时间都是 300)
  • 内存限制是多少?
  • 内存限制为-1(无限制)
  • 还没有。我拥有的最小文件是 7mb 文件(这些是我要上传的视频,必须为 1280 x 720)。我会尝试找到一个较小的视频。
  • 不检查分辨率可以成功上传7mb。
【解决方案2】:

尝试使用以下设置调整您的 php.ini:

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

并确保file_uploads 设置在On

【讨论】:

  • 我将此添加到 php.ini 并仔细检查了 file_uploads 是否打开。问题依然存在。
【解决方案3】:

对于遇到此问题的任何人。我不得不增加默认设置为 8M 的 post_max_size。

【讨论】:

    猜你喜欢
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2012-06-04
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    相关资源
    最近更新 更多