javascript - Return new file name from mini-upload-form -


i'm using mini ajax upload form upload files server. modified upload code add time stamp the end of file. how can return new name of file (with time stamp) client later use?

date_default_timezone_set('america/new_york');  $date = date('.ymdhis'); // list of permitted file extensions $allowed = array('sqlite', 'db', 'db3'); if(isset($_files['upl']) && $_files['upl']['error'] == 0){      $extension = pathinfo($_files['upl']['name'], pathinfo_extension);      if(!in_array(strtolower($extension), $allowed)){             echo '{"status":"error"}';             exit;     }      $file =  '/var/www/html/uploads/'.$_files['upl']['name'].$date;      if(move_uploaded_file($_files['upl']['tmp_name'], $file)){             echo '{"status":"success"}';             exit;     } } echo '{"status":"error"}'; exit; 

js:

$(function(){   $('#drop a').click(function(){     // simulate click on file input button     // show file browser dialog     $(this).parent().find('input').click();  });   // initialize jquery file upload plugin  $('#upload').fileupload({      url: 'includes/php/upload.php',      // element accept file drag/drop uploading     dropzone: $('#drop'),  });   // prevent default action when file dropped on window  $(document).on('drop dragover', function (e) {     e.preventdefault();  }); }); 

html snippet:

<div class="row">  <div class="col-lg-12 text-center">   <form id="upload" method="post" enctype="multipart/form-data">    <div id="drop">     <p>drop database here</p>     <a>browse</a>     <input type="file" name="upl" multiple/>    </div>   </form>  </div> </div> 

note: mini ajax upload form uses jquery-file-upload

you can use done call file name after upload it, of course need write ajax in php script

done: function (e, data) {             $("tr:has(td)").remove();             $.each(data.result, function (index, file) {                  $("#uploaded-files").append(                         $('<tr/>')                         .append($('<td/>').text(file.filename))                         .append($('<td/>').text(file.filesize))                         .append($('<td/>').text(file.filetype))                         .append($('<td/>').html("<a href='upload?f="+index+"'>click</a>"))                         .append($('<td/>').text("@"+file.twitter))                          )//end $("#uploaded-files").append()             });          }, 

also example java example similar thing http://hmkcode.com/java-servlet-jquery-file-upload/


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -