Unexcepted error on upload but upload success

3 posts, 0 answers
  1. Daniel Botero Correa
    Daniel Botero Correa avatar
    32 posts
    Member since:
    Oct 2009

    Posted 17 Apr 2012 Link to this post

    Hello,

    I tried to use kendo upload and that works but I get a error message when upload finish.

    Kendo upload does everything right and at the end the file was uploaded but kendo upload says that it had a problem.

    I know that in Save file if response is empty means the process was good otherwise the process had a problem.

    I think the problem is caused because of response of apache, it says that My Content-Length = 2 but really My response was empty.

    I took this examples from kendo examples

    This is the raw view of the response of my web server:

    HTTP/1.1 200 OK
    Date: Tue, 17 Apr 2012 06:31:58 GMT
    Server: Apache/2.2.21 (Win32) PHP/5.3.8
    X-Powered-By: PHP/5.3.8
    Content-Length: 2
    Keep-Alive: timeout=5, max=99
    Connection: Keep-Alive
    Content-Type: text/html


    Code html/js:
    <div id="example" class="k-content">
     
        <div style="width:60%">
            <input name="files[]" id="files" type="file" />
        </div>
     
    </div>
           
        <script>
            $(document).ready(function() {
                $("#files").kendoUpload({
                    async: {
                        saveUrl: 'save.php',
                        removeUrl: 'remove.php',
                        autoUpload: true
                    }
                });
            });

        </script>

    code save.php:

    <?php
        $fileParam = "files";
        $uploadRoot = "c:/upload/";
        $files = $_FILES[$fileParam];
         
        if(!is_dir($uploadRoot))
        {
            mkdir($uploadRoot, 0777, true);
            chmod($uploadRoot, 0777);
        }
     
        if (isset($files['name']))
        {
            foreach ($files["name"] as $i => $name) {
                $error = $files['error'][$i];
     
                if ($error == UPLOAD_ERR_OK) {
                    $targetPath = $uploadRoot . basename($files["name"][$i]);
                    $uploadedFile = $files["tmp_name"][$i];
     
                    if (is_uploaded_file($uploadedFile)) {
                        if (!move_uploaded_file($uploadedFile, $targetPath)) {
                            echo "Error moving uploaded file";
                        }
                    }
                } else {
                    // See http://php.net/manual/en/features.file-upload.errors.php
                    echo "Error code " . $error;
                }
            }
        }
        // Return an empty string to signify success
        echo "";
    ?>

    code remove.php:

    <?php
        $fileParam = "files";
        $uploadRoot = "c:/upload/";
        $fileNames = $_POST["fileNames"];
     
        if (isset($fileNames))
        {
            foreach ($fileNames as $i => $name) {
                $targetPath = $uploadRoot . basename($name);
                if (!unlink($targetPath)) {
                    echo "Error removing file";
                }
            }
        }
     
        // Return an empty string to signify success
        echo "";
    ?>



    Is there a way to configure kendo upload to understand another answer than empty? For example a JSon like {Status:0}

    Thank you,
    Daniel Botero Correa
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2834 posts

    Posted 18 Apr 2012 Link to this post

    Hi,

    What are the chances that the save/remove.php handlers have a trailing space? I believe this will be included in the response.

    I hope this helps.

    Kind regards,
    Tsvetomir Tsonev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Daniel Botero Correa
    Daniel Botero Correa avatar
    32 posts
    Member since:
    Oct 2009

    Posted 20 Apr 2012 Link to this post

    Hi,

    There are no chances that handlers have a trailing space, I tried with a empty file and my response has always a size greater than zero so the content-lengt is always > 0

    But, I found my response in the following page:

    http://www.kendoui.com/documentation/ui-widgets/upload/metadata.aspx

    There they explain the responses with JSON and is pretty good.

    Thank you,
    Daniel
Back to Top