简体   繁体   中英

Can't upload files above 1mb in Dropzone

I used Dropzone to handle the file uploads in my Symfony2 project.

It's working fine if I upload files below 1mb but when I upload a file exceeding 1mb, it throws an exception.

I thought the problem was on the maxFilesize config of Dropzone but it wasn't. It was working since it shows a message that the file size exceeds the max size that I've set.

My form:

<form id="quickUpload" action="{{ path('upload_process') }}" method="put" enctype="multipart/form-data" class="dropzone">
   <div class="fallback">
       <input name="file" type="file" multiple />
   </div>
</form>

Javascript:

Dropzone.options.quickUpload = {
            addRemoveLinks: true,
            dictDefaultMessage: "Drop files to upload (or click)",
            maxFilesize: 5,
            init: function () {
                this.on("success", function (file, response) {
                    file.serverId = response.id;
                });

                this.on("removedfile", function (file) {
                    if (!file.serverId) {
                        return;
                    }
                    var url = "{{ path("delete_upload") }}";
                    $.ajax({
                        url: url,
                        type: 'POST',
                        data: {id: file.serverId},
                        dataType: 'json',
                        success: function (data) {
                            console.log("File Deleted");
                        },
                        error: function () {
                            console.log("File Delete Error");
                        }
                    });
                });
            }
 }

Controller:

/**
 * @Route("/upload_process", name="upload_process")
 * @Method("PUT")
 */
public function uploadProcessAction(Request $request) {

    if ($request->isXmlHttpRequest()) {
        $files = $request->files;
        $em = $this->getDoctrine()->getManager();
        $ids = [];

        foreach ($files as $file) {
            $document = new Document();
            $document->setUploader($this->getUser())
                    ->setFile($file);
            $em->persist($document);
            $ids[] = $document;
        }
        $em->flush();

        return new JsonResponse(['id' => $ids[0]->getId()]);
    }
}

Finally fixed it. I just needed to change the value of the upload_max_filesize in my php.ini file. I saved the file, restarted XAMPP and got it working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM