Created
July 14, 2015 16:46
-
-
Save travisfont/aec034e0706555a2b50e to your computer and use it in GitHub Desktop.
jquery File Upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>File Uploader Example</title> | |
| <script src="//code.jquery.com/jquery-1.9.1.js"></script> | |
| <script type="text/javascript"> | |
| function submitForm() | |
| { | |
| var fd = new FormData(document.getElementById("fileinfo")); | |
| fd.append("label", "WEBUPLOAD"); | |
| $.ajax( | |
| { | |
| url: "upload.php", | |
| type: "POST", | |
| data: fd, | |
| enctype: 'multipart/form-data', | |
| processData: false, | |
| contentType: false | |
| }).done(function (data) | |
| { | |
| var response = JSON.parse(data); | |
| if (response.success !== undefined && response.success == true) | |
| { | |
| $('#file').val(''); | |
| $('#file_upload').append('<a href="/uploads/'+response.file.full+'" target="_new">'+response.file.short+'</a><br/>'); | |
| } | |
| }); | |
| return false; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <form method="post" id="fileinfo" name="fileinfo" onsubmit="return submitForm();"> | |
| <!-- <label>Select a file:</label><br> --> | |
| <input type="file" name="file" id="file" required /> | |
| <div id="file_upload"></div> | |
| <p><input type="submit" value="Upload" /></p> | |
| </form> | |
| <div id="output"></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment