thebigsmileXD

form upload

Jun 29th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>HTML5 - Upload-Thumbnails (Vorschau) erstellen</title>
  5. </head>
  6. <body>
  7. <style type="text/css">
  8. #thumbnail img {padding:4px;max-width:100px;max-height:100px;}
  9. </style>
  10.  
  11. <script type="text/javascript">
  12. function fileThumbnail(files)
  13. {
  14. var thumb = document.getElementById("thumbnail");
  15.  
  16. thumb.innerHTML = "";
  17.  
  18. if(!files)
  19. return;
  20.  
  21. for(var i = 0; i < files.length; i++)
  22. {
  23. var file = files[i];
  24.  
  25. if(!file.type.match(/image.*/))
  26. continue;
  27.  
  28. var img = document.createElement("img");
  29. var reader = new FileReader();
  30.  
  31. reader.onload = (function(tImg) {
  32. return function(e) {
  33. tImg.src = e.target.result;
  34. };
  35. })(img);
  36.  
  37. reader.readAsDataURL(file);
  38. thumb.appendChild(img);
  39. }
  40. }
  41. </script>
  42.  
  43. <form method="post" enctype="multipart/form-data" action="upload.php">
  44. Name<input type="text" name="name">
  45. <input type="file" name="image" accept="image/*" onChange="fileThumbnail(this.files);">
  46. <!--<input type="file" name="fileInput" accept="image/*" multiple onChange="fileThumbnail(this.files);">//-->
  47. <input type="submit" value="Hochladen">
  48. </form>
  49.  
  50. <div>
  51. <div id="thumbnail"></div>
  52. </div>
  53. </body>
  54. </html>
  55.  
  56.  
  57.  
  58. -------------------------------------
  59.  
  60.  
  61. <?php
  62. print_r($_POST);/*
  63. require_once('/main/class.upload.php');
  64. $name=$_POST['name'];
  65. $foo = new Upload($_FILES['image']);
  66. if ($foo->uploaded) {
  67. $foo->file_new_name_body = 'avatar';
  68. $foo->image_resize = true;
  69. $foo->image_convert = png;
  70. $foo->image_x = 100;
  71. $foo->image_y = 100;
  72. $foo->image_ratio = true;
  73. $foo->Process($name);
  74. if ($foo->processed) {
  75. echo 'image renamed, resized x,y=100
  76. and converted to png';
  77. $foo->Clean();
  78. } else {
  79. echo 'error : ' . $foo->error;
  80. }
  81. } */
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment