Guest User

Untitled

a guest
Oct 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2. require 'header.php';
  3. print '
  4. <div class="laatikko" style="margin-top:40px;">
  5. <div class="box-wrap" style="width:500px";>
  6. <div class="box-header">File Upload</div>
  7. <div class="box">
  8. <span class="class2">';
  9. if (isset($_COOKIE['login'])) {
  10. print '
  11. <form action="upload.php" method="post"
  12. enctype="multipart/form-data">
  13. <label for="file">Tiedosto:</label>
  14. <input type="file" name="file" id="file" />
  15. <br />
  16. <input type="submit" name="submit" value="Lähetä" />
  17. </form>';
  18.  
  19. if ((($_FILES["file"]["type"] == "image/gif")
  20. || ($_FILES["file"]["type"] == "image/jpeg")
  21. || ($_FILES["file"]["type"] == "image/png")
  22. || ($_FILES["file"]["type"] == "text/plain")
  23. || ($_FILES["file"]["type"] == "image/pjpeg"))
  24. && ($_FILES["file"]["size"] < 2000000))
  25. {
  26. if ($_FILES["file"]["error"] > 0)
  27. {
  28. echo "Palautus: " . $_FILES["file"]["error"] . "<br />";
  29.  
  30. } else {
  31. echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  32. echo "Muoto: " . $_FILES["file"]["type"] . "<br />";
  33. echo "Koko: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  34.  
  35. if (file_exists("up/" . $_FILES["file"]["name"]))
  36. {
  37. echo $_FILES["file"]["name"] . " already exists. ";
  38. }
  39. else {
  40. move_uploaded_file($_FILES["file"]["tmp_name"], "up/" . $_FILES["file"]["name"]);
  41. echo 'Tallennettu: <a href="up/' . $_FILES["file"]["name"] . '">' . $_FILES["file"]["name"] . '</a>';
  42.  
  43. $thumb = new Imagick("up/" . $_FILES["file"]["name"]);
  44. $thumb->setImageOpacity(1.0);
  45. $geo = $thumb->getImageGeometry();
  46. list($newX,$newY) = scaleImage(
  47. $geo["width"],
  48. $geo['height'],
  49. 100,
  50. 100
  51. );
  52.  
  53. $thumb->resizeImage($newX,$newY,Imagick::FILTER_POINT | Imagick::INTERLACE_GIF,1); # force thumbnail to have 100px width
  54. $thumb->writeImage("up/thumb/". $_FILES["file"]["name"]); # write to thumb
  55. $thumb->clear();
  56. $thumb->destroy();
  57.  
  58. }
  59. }
  60. }
  61. else {
  62. if (isset($_FILES["file"])) {
  63. echo "Kielletty tiedostoformaatti";
  64. }
  65. }
  66. print '</span>
  67. </div>
  68. </div>
  69. <div class="box-wrap" style="width:500px">
  70. <div class="box-header">Tiedostot</div>
  71. <div class="box-filelist">
  72. <span class="class2">';
  73.  
  74. foreach (glob("up/*") as $filename) {
  75. print '<a href="' . $filename . '"><img src="' . $filename . '"></a><br />';
  76.  
  77. }
  78.  
  79. } else {
  80. print 'Sinun täytyy ensin kirjautua sisään';
  81. }
  82.  
  83.  
  84. print '
  85. </span>
  86. </div>
  87. </div>
  88. </div>';
  89. require 'footer.php';
  90. ?>
Add Comment
Please, Sign In to add comment