javascript - I'm having some trouble making a multi-file uploader in PHP -


My goal is a website where I can upload many files to my webserver. This is my html form:

  & lt; form class = 'form-horizontal' & gt; & Lt; div class = 'form-group text-center' & gt; & Lt; H3 & gt; Upload & lt; / H3 & gt; & Lt; / Div & gt; & Lt; Div class = 'form-group' & gt; & Lt; label = 'file' class = 'col-sm-3-control-label' & gt; Label for file & lt; / Label & gt; & Lt; div class = 'col-sm-9' & gt; & Lt; Input type = "file" id = 'files' class = "form-control text-center" multiple /> & Lt; / Div & gt; & Lt; div class = 'col-sm-12' & gt; & Lt; Br> & Lt; Button Type = "Button" id = 'submit' class = "BTN BTN-Success Center-Block Glyphicon Glyphicon-Cloud-Uploaded BTN-LG" Value = 'Upload' / & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Form & gt;   

Then here's my javascript:

  $ (document) .ready (function () {var files = []; $ ("# files" ) .bind ('change', function () {files = this.files}); $ ("# submit") Click (function () {// if first (files.length & gt; 0) {var data Validate = {files: files}; $ .exax ({type: "post", url: "& lt ;? php echo bases_im;; & gt; / file uploader / php / upload files.php", data: data, Success: Function {Console.log (response); // $ ("#file"). Val ("");}})}}});});   

As soon as I send my AJAX request, I get an error in the console: "Uncort type error: invalid greeting in jquery.min.ms file"

Does anyone know how to fix this?

I did this by using PHP, Javascript and AJAX from last summer. This will work for image, audio, video, textile files.

HTML

  & lt; body & gt; & Lt; H1 & gt; Media uploads & lt; / H1> & Lt; Form name = "upload_product" id = "upload_product" method = "post" encrypt = "multipart / form-data" & gt; Choose image: & lt; Input type = "file" id = "uploadimage" name = "uploadimage" /> & Lt; Br / & gt; & Lt; Input type = "button" value = "upload image" name = "upload button" onclick = "showprogressbar ();" /> Format allowed: "jpg" "gif", "png" only & Lt; Br / & gt; & Lt; div id = "progressDiv" style = "display: none" & gt; & Lt; Progress ID = "progress big" value = "0" max = "100" style = "width: 300px;" & Gt; & Lt; / Progress & gt; & Lt; / Div & gt; & Lt; H3 id = "status" & gt; & Lt; / H3 & gt; & Lt; P id = "loaded_n_total" & gt; & Lt; / P & gt; Choose video: & lt; input type = "file" id = "uploadvideo" name = "upload_video" /> & Lt; Br / & gt; & Lt; Input type = "button" value = "upload video" name = "upload button" onclick = "showprogressbar2 ();" /> Format permission: "mp4" only & Lt; Br / & gt; & Lt; div id = "progressDiv2" style = "display: none" & gt; & Lt; Progress id = "progressBar2" name = "progress bar 2" value = "0" max = "100" style = "width: 300px;" & Gt; & Lt; / Progress & gt; & Lt; / Div & gt; & Lt; H3 id = "status2" & gt; & Lt; / H3 & gt; & Lt; P id = "loaded_n_total2" & gt; & Lt; / P & gt; & Lt; / Form & gt; & Lt; / Body & gt;   

PHP

  $ fileName = $ _FILES ["uploaded"] ["name"]; // file name $ fileTmpLoc = $ _FILES ["uploadmap"] ["tmp_name"]; // file in PHP tmp folder $ fileType = $ _FILES ["uploaded"] ["type"]; // File type is $ fileSize = $ _FILES ["uploaded"] ["size"]; // file size bytes $ fileErrorMsg = $ _FILES ["uploadimage"] ["error"]; // is wrong for 0 and 1 ...   

The PHP and JavaScript code is a bit long so that you can read them Go to the given geithub link < / Strong>.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -