T
T
The Dragger2015-04-08 11:03:52
JavaScript
The Dragger, 2015-04-08 11:03:52

How to fix Server responded with 0 code error?

Decided to install dropzone programmatically on yii.
js code

$(function() {
            var dzone = new Dropzone("#dropZed", {
                paramName: "img_url",
                url: "/admin/MyGallery/ImagesUpload",
                method: "files",
                autoProcessQueue: false,
                addRemoveLinks: true,
                init: function() {
                    var submitButton = document.querySelector("#sb-all");
                    dzone = this; // closure

                    submitButton.addEventListener("click", function() {
                        dzone.processQueue(); // Tell Dropzone to process all queued files.
                    });
                }
            });
                Dropzone.autoDiscover = false;
        });

and php handler
public function actionImagesUpload(){
        $model = new MyGallery;
        if($_FILES['img_url']){
            if($_FILES['img_url']['error'] == 0){
                move_uploaded_file($_FILES['img_url']['tmp_name'],
                    Yii::app()->request->baseUrl . 'images/upload/' . $_FILES['img_url']['name']);
            }}
        $model->img_url = $_FILES['img_url']['name'];
        $model->save();
    }

in Mozile the error Server responded with 0 code in Chrome - Undefined index img_url;
Anyone have any ideas to fix this error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Papa, 2015-04-08
Stifflera @PapaStifflera

And if so:

public function actionImagesUpload()
    {
        $model = new MyGallery;
        if(isset($_FILES['img_url'])){
            if($_FILES['img_url']['error'] == 0){
                move_uploaded_file($_FILES['img_url']['tmp_name'],
                    Yii::app()->request->baseUrl . 'images/upload/' . $_FILES['img_url']['name']);
            }
            $model->img_url = $_FILES['img_url']['name'];
            $model->save();
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question