Guest User

upload.php

a guest
Oct 31st, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $server = "db707706878.db.1and1.com:3306";
  4. $username = "dbo707706878";
  5. $password = "p135qDdbH@ndl3r";
  6. $dbname = "db707706878";
  7. $conn = new mysqli($server,$username,$password,$dbname);
  8. if ($conn->connect_error) {
  9. die("Connection failed: " . $conn->connect_error);
  10. }
  11. $target_dir = "uploads/";
  12. $userid = $_SESSION['userid'];
  13. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  14. echo "$target_file";
  15. $uploadOk = 1;
  16. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  17. // Check if file already exists
  18. if (file_exists($target_file)) {
  19. echo "Sorry, file already exists.";
  20. $uploadOk = 0;
  21. }
  22. // Check file size
  23. if ($_FILES["fileToUpload"]["size"] > 50000000) {
  24. echo "Sorry, your file is too large.";
  25. $uploadOk = 0;
  26. }
  27. // Allow certain file formats
  28. if($imageFileType != "mp4") {
  29. echo "Sorry, only MP4 files are allowed.";
  30. $uploadOk = 0;
  31. }
  32. // Check if $uploadOk is set to 0 by an error
  33. if ($uploadOk == 0) {
  34. die(" <a href='request.php'>Click here to return</a>");
  35. // if everything is ok, try to upload file
  36. } else {
  37. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  38. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  39. echo " <a href='exit.php'>Click here to log out</a>";
  40. $sql = "
  41. UPDATE `db707706878`.`users` SET `uploaded` = '1' WHERE `users`.`id` = $userid;";
  42. $result = $conn->query($sql);
  43. } else {
  44. echo "Sorry, there was an error uploading your file.";
  45. die(" <a href='request.php'>Click here to return</a>");
  46. }
  47. }
  48. ?>
Add Comment
Please, Sign In to add comment