Advertisement
rawyon

Untitled

May 4th, 2011
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.    <head>  
  4.       <title>Upload an image</title>
  5.    </head>
  6.    </body>
  7.       <form action="test.php" method="POST" enctype="multipart/form-data">
  8.          <p>Ladda upp bild.</p>
  9.          <input type="file" name="image">
  10.          <input type="submit" value="Upload">
  11.       </form>
  12.    </body>
  13. </html>
  14.  
  15. <?php
  16. //anslut
  17. require "anslut.php";
  18.  
  19. //file properties
  20. $file = $_FILES['image'] ['tmp_name'];
  21.  
  22. if(!isset($file)) {
  23.    echo "Please selecet an image.";
  24.    } else {
  25.       $image = file_get_contents($_FILES['image'] ['tmp_name']);
  26.       $image_name = $_FILES['image'] ['name'];
  27.       $image_size = getimagesize($_FILES['image'] ['tmp_name']);
  28.  
  29.       if ($image_size==FALSE){
  30.          echo "Thatś not an image.";
  31.       } else {
  32.       if (!$insert = mysql_query("INSERT INTO images VALUES ('', '$image_name', '$image')")) {
  33.          echo "Problem uploading image";
  34.          } else {
  35.          $lastid = mysql_insert_id();
  36.          echo  "image uploaded.<p />Your image:<p /><img src=get.php?id=$lastid>";
  37.          }
  38.       }
  39.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement