Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP form processing ERROR in uploading image

Tags:

html

forms

php

Am using HTML to upload images and process form in PHP in my form i need the following

  • Maximum file only 5 file user can upload
  • i need to store all image name to SQL database

HTML

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

SCRIPT

<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            if (window.File && window.FileList && window.FileReader) {
                $("#files").on("change", function(e) {
                    var files = e.target.files,
                            filesLength = files.length;
                    for (var i = 0; i < filesLength; i++) {
                        var f = files[i]
                        var fileReader = new FileReader();
                        fileReader.onload = (function(e) {
                            var file = e.target;
                            $("<img></img>", {
                                class: "imageThumb",
                                src: e.target.result,
                                title: file.name
                            }).insertAfter("#files");
                        });
                        fileReader.readAsDataURL(f);
                    }
                });
            } else {
                alert("Your browser doesn't support to File API")
            }
        });
    </script>

FORM PROCESSING

$file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING);
$file1 = filter_input(INPUT_POST, 'file1', FILTER_SANITIZE_STRING);
$file2 = filter_input(INPUT_POST, 'file2', FILTER_SANITIZE_STRING);
$file3 = filter_input(INPUT_POST, 'file3', FILTER_SANITIZE_STRING);
$file4 = filter_input(INPUT_POST, 'file4', FILTER_SANITIZE_STRING);

withe the above code i need to store image name to SQL database

like image 433
sanoj lawrence Avatar asked Sep 27 '14 18:09

sanoj lawrence


1 Answers

I would suggest that you take a look here :

how can I upload multiple files at a single browse using jquery or JavaScript

and here :

Count and limit the number of files uploaded (HTML file input)

like image 153
Michael Laffargue Avatar answered Sep 22 '22 05:09

Michael Laffargue