doucha4054 2015-08-11 14:02
浏览 46

Php Ajax大文件上传失败

I currently have a php api using REST which has the following method:

private function createVideoCast(){
            if($this->get_request_method() != "POST"){
                $error = array('status' => "Failed", "msg" => "Invalid Request Method");
                $this->response($this->json($error), 406);
            }
            else{
                $vid    = (int)$this->getLastVideoCastId() + 1;
                $date   = $this->_request['date'];
                $video  = $this->_files['video'];

                if(!empty($video['name']) && !empty($date)){
                    $vorder = (int)$this->getLastVideoCastVorder($date) + 1;

                    $vidExts = array("video/mp4");

                    if(!in_array($video['type'], $vidExts)){
                        $error = array('status' => "Failed", "msg" => "Video Must Be Of Type MP4");
                        $this->response($this->json($error), 400);
                    }
                    if($video['size'] > 1073741824){
                        $error = array('status' => "Failed", "msg" => "Video Maximum Size Is 1GB");
                        $this->response($this->json($error), 400);
                    }

                    $desired_base_dir   = "videocasts/".$date;
                    if(is_dir($desired_base_dir) == false){
                        mkdir($desired_base_dir);
                        $video_name = $vorder.".mp4";

                        if(is_dir($desired_base_dir."/".$video_name) == false){
                            move_uploaded_file($video['tmp_name'], $desired_base_dir."/".$video_name);
                        }
                        else{
                            unlink($desired_base_dir."/".$video_name);
                            move_uploaded_file($video['tmp_name'], $desired_base_dir."/".$video_name);
                        }
                        $video_path = $desired_base_dir."/".$video_name;

                        $sql = "INSERT QUERY TO MY DATABASE";

                        if(mysql_query($sql, $this->db)){
                            $success = array('status' => "Success", "msg" => "Video Successfully Uploaded.");
                            $this->response($this->json($success), 200);
                        }
                        else{
                            $error = array('status' => "Failed", "msg" => mysql_error());
                            $this->response($this->json($error), 400);
                        }
                    }
                }
                else{
                    $error = array('status' => "Failed", "msg" => "Date & Video Required");
                    $this->response($this->json($error), 400);
                }
            }
        }

And I have a html form submitting to this via ajax as shown below:

<script type="text/javascript">
        function _(el){
            return document.getElementById(el);
        }
        function createVideoCast(){
            var date  = _("date").value;
            var video = _("video").files[0];

            var formdata = new FormData();
            formdata.append("date", date);
            formdata.append("video", video);

            var ajax = new XMLHttpRequest();
            ajax.upload.addEventListener("progress", progressHandler, false);
            ajax.addEventListener("load", completeHandler, false);
            ajax.addEventListener("error", errorHandler, false);
            ajax.addEventListener("abort", abortHandler, false);
            ajax.open("POST", "../newsApi.php?rquest=createVideoCast");
            ajax.send(formdata);
        }
        function progressHandler(event){
            var percent = (event.loaded / event.total) * 100;
            _("progressBar").value = Math.round(percent);
            _("upload-status").innerHTML = Math.round(percent)+"%";
        }
        function completeHandler(event){
            console.log(event);
            var message = JSON.parse(event.target.responseText);
            _("message").innerHTML = message.msg;
            _("progressBar").value = 0;

            if(message.msg == "VideoCast Successfully Created."){
                _("vc-form").reset();
            }
        }
        function errorHandler(event){
            console.log(event);
            _("message").innerHTML = "Upload Failed";
        }
        function abortHandler(event){
            _("message").innerHTML = "Upload Aborted";
        }
    </script>

It works perfectly for videos under approximately 250MB but once the video exceed that size I get the following error:

"<-- SHTML Wrapper - 500 Server Error -->↵[an error occurred while processing this directive]↵"

My php.ini file settings is set to cater for 1GB files. I hope someone can provide some assistance to this, thanks in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区
    • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
    • ¥15 NAO机器人的录音程序保存问题
    • ¥15 C#读写EXCEL文件,不同编译
    • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符