Guest User

Untitled

a guest
Jun 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. if (isset($_SESSION['allowUpload']) {
  2. // OK
  3. } else {
  4. // please login or you are not allowed to upload
  5. }
  6.  
  7. <form action="upload.php" method="post" enctype="multipart/form-data">
  8. Select image to upload:
  9. <input type="file" name="fileToUpload" id="fileToUpload">
  10. <input type="submit" value="Upload Image" name="submit">
  11. </form>
  12.  
  13. <?php
  14. if(!User->isLogged()){ // or $_SESSION
  15. return false; //or header('Location: login.php')
  16. }
  17. $target_dir = "uploads/";
  18. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  19. $uploadOk = 1;
  20. $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  21. // Check if image file is a actual image or fake image
  22. if(isset($_POST["submit"])) {
  23. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  24. if($check !== false) {
  25. echo "File is an image - " . $check["mime"] . ".";
  26. $uploadOk = 1;
  27. } else {
  28. echo "File is not an image.";
  29. $uploadOk = 0;
  30. }
  31. }
  32. ?>
Add Comment
Please, Sign In to add comment