Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form enctype="multipart/form-data" method="post">
- <input name="files[]" type="file" id="upload_file" /><br/>
- <input type="button" id="upload" value="Upload File" />
- </form>
- $("#upload_file").hide();
- $("#upload").click(function() {
- $("#upload_file").click();
- })
- $('#upload_file').change(function(e) {
- e.preventDefault();
- var formData = new FormData($(this).parents('form')[0]);
- $.ajax({
- url: '___ajax_upload_files.php',
- type: 'POST',
- xhr: function() {
- var myXhr = $.ajaxSettings.xhr();
- return myXhr;
- },
- success: function (data) {
- $('#upload_span').html( data );
- },
- data: formData,
- cache: false,
- contentType: false,
- processData: false
- });
- return false;
- })
- if ( !empty( $_FILES['files']['name'] ) ) {
- $target_path = '../images/';
- $ext = explode('.', basename( $_FILES['files']['name'] ) );
- $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext)-1];
- $val_img = substr( $target_path , 10 );
- //Here code to display uploaded image
- if(move_uploaded_file($_FILES['files']['tmp_name'][$i], $target_path)) {
- echo '<a href=""><img src="../images/'. $val_img. '" ></a> ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement