0

我不明白codeigniter的上传过程。我添加了一个最大文件大小,并且在永远尝试之后它会拒绝视频,但是我怎样才能检查文件大小,如果文件太大(超过 4GB)甚至不尝试上传?

在下面的这段代码中,我无法获取视频数据本身?如何在尝试使用 do_upload 函数之前检查上传大小,如果文件太大则重定向?

  private function upload_video()
    {
        $data = $this->input->post();
        $customerUploadPath = FCPATH . 'uploads/publishers/' . $data['publisher_id'];
        if (!file_exists($customerUploadPath)) {
            mkdir($customerUploadPath, 0775);
        }
        $videoUploadPath = $customerUploadPath . '/videos';
        if (!file_exists($videoUploadPath)) {
            mkdir($videoUploadPath, 0775);
        }
        $videoUploadPath .= "/";
        $videoConfig = [
            'file_name' => date("YmdHis"),
            'upload_path' => $videoUploadPath,
            'allowed_types' => 'mov|mpg|mp4|m4a',
            'overwrite' => true,
            'max_size' => 350000000
        ];

        $this->load->library('upload', $videoConfig);
        if (!$this->upload->do_upload('video')) {
            $response = ['success' => false, 'error' => $this->upload->display_errors()];
            log_message('error', 'Video file upload error. User: ' . $this->user['id'] . ' Error: ' . $this->upload->display_errors());
        } else {
            $uploadData = $this->upload->data();
            $ffprobe = FFMpeg\FFProbe::create();
            if ($ffprobe->isValid($videoUploadPath . $uploadData['file_name'])) {
                $duration = $ffprobe->format($videoUploadPath . $uploadData['file_name'])->get('duration');
                $ffmpeg = FFMpeg\FFMpeg::create();
                $video = $ffmpeg->open($videoUploadPath . $uploadData['file_name']);
                $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10));
                $thumbnail_file = $uploadData['raw_name'] . '.jpg';
                $frame->save($videoUploadPath . $thumbnail_file);
                $data = ['video_file' => $uploadData['file_name'], 'duration' => $duration, 'thumbnail_file' => $thumbnail_file];
                $response = ['success' => true, 'data' => $data];
            } else {
                log_message('error', 'Invalid video file uploaded. User: ' . $this->user['id']);
                $response = ['success' => false, 'error' => 'Invalid video file.'];
            }
        }
        return $response;
    }
4

0 回答 0