uploader.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. {% if title == "Início" %}
  2. {% set title = "Início" %}
  3. {% elseif title == "Tag" %}
  4. {% set title = "Tag: " + tag %}
  5. {% endif %}
  6. {% extends 'layout.html' %}
  7. {% block body %}
  8. <div class="container-fluid">
  9. {% if messages.success %}
  10. <div role="alert" class="alert alert-success">
  11. {% for success in messages.success %}
  12. <div>{{ success.msg }}</div>
  13. {% endfor %}
  14. </div>
  15. {% endif %}
  16. {% if messages.error %}
  17. <div role="alert" class="alert alert-danger">
  18. {% for error in messages.error %}
  19. <div>{{ error.msg }}</div>
  20. {% endfor %}
  21. </div>
  22. {% endif %}
  23. {% if messages.info %}
  24. <div role="alert" class="alert alert-info">
  25. {% for info in messages.info %}
  26. <div>{{ info.msg }}</div>
  27. {% endfor %}
  28. </div>
  29. {% endif %}
  30. </div>
  31. <h2>Uploader de Imagem</h2>
  32. <section class="work">
  33. {% if user.mod %}
  34. <br><br><br>
  35. <input id="upload-input3" type="file" accept="image/jpg, image/jpeg">
  36. <img3></img3>
  37. {% endif %}
  38. <div class="centerBlock">
  39. <!--<a class="btn" href="#">Ver todo o conteúdo</a>-->
  40. </div>
  41. </section>
  42. <script type="text/javascript">
  43. var f3 = document.getElementById('upload-input3');
  44. f3.onchange = function(e){
  45. var ext = this.value.match(/\.(.+)$/)[1];
  46. switch(ext)
  47. {
  48. case 'jpg':
  49. case 'png':
  50. break;
  51. default:
  52. alert('Formato de arquivo inválido.');
  53. this.value='';
  54. }
  55. };
  56. $('#upload-input3').on('change', function(){
  57. var files = $(this).get(0).files;
  58. if (files.length > 0){
  59. // create a FormData object which will be sent as the data payload in the
  60. // AJAX request
  61. var formData = new FormData();
  62. // loop through all the selected files and add them to the formData object
  63. for (var i = 0; i < files.length; i++) {
  64. var file = files[i];
  65. // add the files to formData object for the data payload
  66. formData.append('uploads[]', file, file.name);
  67. }
  68. $.ajax({
  69. url: '/upload',
  70. type: 'POST',
  71. data: formData,
  72. processData: false,
  73. contentType: false,
  74. success: function(data){
  75. console.log('upload successful!\n' + data);
  76. $( "img3" ).html( "<input name='none' style='' size='70' value='" + data + "'>");
  77. },
  78. });
  79. }
  80. });
  81. </script>
  82. {% endblock %}