1

When uploading image files, the upload is complete and successful, but when uploading the video file, it is not uploaded and it does not show where the error is

HTML Code:

           <div class="row mb-5">
                <div class="col-md-12">
                    <input type="file" name="slider_image" id="" class="form-control mb-5" onchange="homeSliderUpload(this)">
                    <div class="progress mb-5" style="--sa-progress--value: 0%">
                        <div class="progress-bar progress-bar-sa-primary" role="progressbar" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function homeSliderUpload(form) {
        alert("First");
        var file_data = $("input[name='slider_image']").prop('files')[0];
        var form_data = new FormData();
        form_data.append('file', file_data);
        $.ajax({
            url: "<?php echo base_url(); ?>/Path/VedioUploader",
            dataType: 'text',
            method: "post",
            cache: false,
            contentType: false,
            processData: false,
            data: form_data,
            success: function(data) {
                var rJson = $.parseJSON(data);
                if (rJson.status == true) {
                    $(".progress").attr("style", "--sa-progress--value: 100%");
                    $("input[name='slider_image']").val('');

                    setInterval(() => {
                        location.reload();
                    }, 1000);
                } else {
                      alert("Error");
                }
            }
        });
    }

php Code ( Ajax Code):

public function VedioUploader()
    {
        $validateImage = $this->validate([
            'file' => [
                'uploaded[file]',
                'mime_in[file, video/mp4, image/png, image/jpg,image/jpeg, image/gif]',
                'max_size[file, 1000000000]',
            ],
        ]);

        if ($validateImage) {
            $imageFile = $this->request->getFile('file');
            $folder = "Vedio/";
            $fileName = rand(10005, 100005) . time() . ".mp4";
            $imageFile->move($folder, $fileName);
            $data = [
                'img_name' => $imageFile->getClientName(),
                'file'  => $imageFile->getClientMimeType(),
                'type' => $imageFile->getClientExtension(),
            ];

            if ($fileName) {
                $homeSliderModel = new VedioUplaod();
                $home_slider["slider_file_url"] = $folder . "/" . $fileName;
                $home_slider["slider_show"] = 1;
                $home_slider["slider_order"] = 0;
                $homeSliderModel->insert($home_slider);

                if (!$homeSliderModel->errors()) {
                    echo json_encode([
                        "status" => true,
                        "slider_id" => $homeSliderModel->getInsertID(),
                        "file_url" => $folder . "/" . $fileName,
                        "order" => 0
                    ]);
                }
            }
        }
    }

I tried removing the image types and retrying to upload the images, but it didn't work. It was similar to uploading the video. I thought it was because of the type, but nothing happened.

'mime_in[file, video/mp4]',
FREE SPEED
  • 19
  • 1
  • Check your PHP configuration specifically `upload_max_filesize = 256M` `post_max_size = 256M`. It is quite possibly just that the video file is hitting the limit whereas the much smaller image file is fine. – Jordan Dec 20 '22 at 11:40
  • which video mime file are you uploading? what is the filesize you try to upload. mimes.php might need to be updated. Is your production server on a shared hosting, what is their politics? – Vickel Dec 20 '22 at 21:06

0 Answers0