2

I am using multiple file upload for this blueimp plugin demo, doc

They are given file upload by the AJAX file. But, I dont need to upload by Ajax. I need $_FILES details in same page while form submitting.

I have tried following code:

<form id="fileupload" action="" method="POST" enctype="multipart/form-data">

    <div class="row fileupload-buttonbar">
        <div class="col-lg-7">

            <span class="btn btn-success fileinput-button">
                <i class="glyphicon glyphicon-plus"></i>
                <span>Add files...</span>
                <input type="file" name="files[]" multiple>
            </span>
            <button id='subtest' type="submit" class="btn btn-primary start">
                <i class="glyphicon glyphicon-upload"></i>
                <span>Start upload</span>
            </button>

        </div>

    </div>
   </form>
<script>
    $('#subtest').click(function() {

        $('#fileupload').submit();
    });
</script>

PHP Script:

<?php
    if(isset($_POST)) {

        print_r($_FILES);
    }
?>

I got following $_FILES result while submitting the form.

Array
(
    [files] => Array
        (
            [name] => Array
                (
                    [0] => 
            )

        [type] => Array
            (
                [0] => 
            )

        [tmp_name] => Array
            (
                [0] => 
            )

        [error] => Array
            (
                [0] => 4
            )

        [size] => Array
            (
                [0] => 0
            )

    )

I dont know why result become likes above. (UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded).

Help me... Thanks in advance.

user2731645
  • 487
  • 1
  • 4
  • 9
  • Change `name="files[]"` for `name="files"` the `multiple` attribute should hand it as an array for you – SparK Feb 06 '14 at 13:25
  • 1
    No the name="files[]" should be fine, I just checked and its working using the exact code. – Abhik Chakraborty Feb 06 '14 at 13:27
  • @SparK the same result coming for $_FILES. – user2731645 Feb 06 '14 at 13:28
  • try to change the name of the field – Rakesh Shetty Feb 06 '14 at 13:28
  • @RakeshShetty it will only change the array key... – SparK Feb 06 '14 at 13:30
  • @RakeshShetty I have changed as 'name=filetest[]' result becomes Array ( [filetest] => Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) ) ) – user2731645 Feb 06 '14 at 13:31
  • So... you don't need AJAX upload, but you are using a plugin whose sole purpose is to provide AJAX upload functionality? "I don't need a hat, how can I make my hat go away?" – Jon Feb 06 '14 at 13:32
  • @Jon for TODO operation of client side.. please see the demo http://blueimp.github.io/jQuery-File-Upload/ – user2731645 Feb 06 '14 at 13:37
  • CHeck if your form is having anything as name="MAX_FILE_SIZE" if so remove this this can create issues on upload if uploading size is more than specified one. – Abhik Chakraborty Feb 06 '14 at 13:52
  • Check here http://stackoverflow.com/questions/3586919/why-would-files-be-empty-when-uploading-files-to-php, also check if some .htaccess is restricting it. – Abhik Chakraborty Feb 06 '14 at 13:56
  • @CHeck there is no field in that name. Now i found out the problem is JS files affecting that. bcoz If i remove the form id 'fileupload' means, it works fine. – user2731645 Feb 06 '14 at 13:57
  • 1
    i see it may the JS lib is doing some sort of disabling the form by that id, try using some other id and use the JS submit. its definitely some other js getting triggered from the library. – Abhik Chakraborty Feb 06 '14 at 14:04

4 Answers4

0

Just close your form tag and try again. following code works on my system

<html>
<body>
<form id="fileupload" action="uploader.php" method="post" enctype="multipart/form-data">

    <div class="row fileupload-buttonbar">
        <div class="col-lg-7">

            <span class="btn btn-success fileinput-button">
                <i class="glyphicon glyphicon-plus"></i>
                <span>Add files...</span>
                <input type="file" name="files[]" multiple>
            </span>
            <button id='subtest' type="submit" class="btn btn-primary start">
                <i class="glyphicon glyphicon-upload"></i>
                <span>Start upload</span>
            </button>

        </div>

    </div>
</form>
    </body>
</html>

uploader.php

<?php
    if(isset($_POST)) {

        print_r($_FILES);
    }
?>
Lal krishnan S L
  • 1,684
  • 1
  • 16
  • 32
0

Try this code since you don't want to submit the form via ajax :-

    <?php
    if(isset($_POST['submit'])) {

        print_r($_FILES);
    }
?>

<form action="" method="POST" enctype="multipart/form-data">

    <div class="row fileupload-buttonbar">
        <div class="col-lg-7">

            <span class="btn btn-success fileinput-button">
                <i class="glyphicon glyphicon-plus"></i>
                <span>Add files...</span>
                <input type="file" name="files[]" multiple>
            </span>
            <input id='subtest' name="submit" type="submit" class="btn btn-primary start">
                <i class="glyphicon glyphicon-upload"></i>
                <span>Start upload</span>
            </button>

        </div>

    </div>



  </form>
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
0

Error 4 means UPLOAD_ERR_NO_FILE means 'No file was uploaded.' you have some problem in your javascript code you using. Check your JavaScript error?

Sanjeev Chauhan
  • 3,977
  • 3
  • 24
  • 30
0

The error you're getting is because no file was uploaded. Check the permissions of your temp folder.

Nathan Dawson
  • 18,138
  • 3
  • 52
  • 58