1

Recently I need to use multiple input type file in one form. But when I post the form its returning null. Like I have nothing on $_POST. I have also add the enctype="multipart/form-data". I am stacked for last 2 days. Googled for many times. But still didn't get any solution. Please help me to out of this.

<form enctype="multipart/form-data" action="/admin/process_post/savepost" method="POST">
            <div class="uk-grid uk-grid-small" data-uk-grid-margin="">
                <div class="uk-width-medium-7-10">

                    <div class="md-card">
                        <div class="md-card-content">
                            <h3 class="heading_a uk-margin-medium-bottom">Add New Canvas</h3>
                            <div class="uk-grid" data-uk-grid-margin>
                                <div class="uk-width-medium-1-1">
                                    <div class="uk-form-row">
                                        <label>Post Title</label>
                                        <input type="text" name="post_title" id="post_title" class="md-input"  />
                                    </div>

                                    <div class="uk-form-row">
                                        <label>Post Description</label>
                                        <textarea id="post_desc" name="post_desc" cols="30" rows="20"></textarea>
                                    </div>

                                </div>
                            </div>

                        </div>
                    </div>


                </div>

                <div class="uk-width-medium-3-10">
                    <div class="md-card">
                        <div class="md-card-content">
                            <div class="uk-form-row">
                                <p>
                                    <input type="checkbox" name="post_status" id="post_status" checked data-md-icheck />
                                    <label for="post_status" class="inline-label">Post Status</label>
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="md-card">
                        <div class="md-card-content">
                            <div class="uk-form-row">
                                <label for="post_attachment" class="inline-label">Post Featured Image</label>
                                <input type="file" id="post_attachment" name="post_attachment">
                            </div>

                        </div>
                    </div>

                    <div class="md-card">
                        <div class="md-card-content">
                            <div class="uk-form-row">
                                <label for="result_img" class="inline-label">Post result Image</label>
                                <input type="file" id="result_img" name="result_img" multiple="multiple">
                            </div>

                        </div>
                    </div>

                    <div class="md-card">
                        <div class="md-card-content">
                            <div class="uk-form-row">
                                <button type="submit" class="uk-form-file md-btn md-btn-primary">Save Post</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>

        </form>

I know this is a silly situation for a developer when they face problem like this.

3
  • Check if you don`t have and error in action url. This form must return something. I have copied it to simple php file with action directed to it, and it return $_POST and $_FILES as it should. Commented Nov 2, 2016 at 20:57
  • Are you sure the problem is with file type? How large are the files you're trying to upload? Commented Nov 2, 2016 at 20:59
  • But when I use one input type file then its working Commented Nov 2, 2016 at 21:05

3 Answers 3

1

Files can be gotten through $_FILES

When doing multiple uploads at same name, name it as array appending [] at end of name example: ( name="images[]" )

If upload continues to appear as empty, and you said in comment that with one file it's doing right, try to change at php.ini post_max_size and upload_max_filesize to a larger amount. Also check max_file_uploads - the number of files allowed for uploads per single request.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I have tried but also nothing found into $_FILES
First check for errors, then check your maximum file upload (MAX) if they are larger then server allows, it will result in empty upload.
Changed the max file upload limit to 750M but not working
Change, post_max_size and upload_max_filesize to a larger amount...
0

Your problem should be your form action, try to put an "/" on the end of it and see if it works:

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

3 Comments

errors where $_POST or $_FILES is null may be cause by passing to form action an url that gets redirection. if your site create redirections on some url pattern, there may be the problem. Install Firebug on Firefox, and set on the "Net" tab, then submit your form an see the result. your action url should be 200 in status. if it is 301 Moved Permanently, this may be the problem
Its post everything with 200 in status. but the $_POST or $_FILES is still blank.
you were able to see all your post data with firebug inspection on "net" tab?
0

You need to change your file input name to an array

<input type="file" id="result_img" name="result_img[]">

Also try adding multiple

<input type="file" id="result_img" name="result_img[]" multiple>  

To check for files you must use $_FILES instead of $_POST

1 Comment

It could be something else. I copy pasted your code, changed file type input names to array then returned print_r($_FILES) and it's working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.