Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. function rrmdir($dir) {
  5. if (is_dir($dir)) {
  6. $files = scandir($dir);
  7. foreach ($files as $file)
  8. if ($file != "." && $file != "..") rrmdir("$dir/$file");
  9. rmdir($dir);
  10. }
  11. else if (file_exists($dir)) unlink($dir);
  12. }
  13.  
  14. function rcopy($src, $dst) {
  15. if (file_exists ( $dst ))
  16. rrmdir ( $dst );
  17. if (is_dir ( $src )) {
  18. mkdir ( $dst );
  19. $files = scandir ( $src );
  20. foreach ( $files as $file )
  21. if ($file != "." && $file != "..")
  22. rcopy ( "$src/$file", "$dst/$file" );
  23. } else if (file_exists ( $src ))
  24. copy ( $src, $dst );
  25. }
  26.  
  27. if (!isset($_SESSION['username'])) {
  28. die("You are not logged in.");
  29. }
  30.  
  31. if ($_POST) {
  32. $title = $_POST['title'];
  33.  
  34. mkdir("../videos/$title");
  35. $target_dir = "../videos/$title/";
  36. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  37.  
  38. echo $target_file;
  39. echo "<br>" . $_FILES["fileToUpload"]["name"];
  40. $uploadOk = 1;
  41. $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  42. if (file_exists($target_file)) {
  43. echo "<div class='error'>File already exists.</div><br>";
  44. $uploadOk = 0;
  45. }
  46. // Check file size
  47. if ($_FILES["fileToUpload"]["size"] > 5000000) {
  48. echo "<div class='error'>File is too big!</div><br>";
  49. $uploadOk = 0;
  50. }
  51. // Allow certain file formats
  52. if($imageFileType != "mp4") {
  53. echo "<div class='error'>Only MP4 files are allowed.</div><br>";
  54. $uploadOk = 0;
  55. }
  56. // Check if $uploadOk is set to 0 by an error
  57. if ($uploadOk == 0) {
  58. echo "<div class='error'>Unknown Error.</div><br>";
  59. // if everything is ok, try to upload file
  60. } else {
  61. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  62. rename ("../$title/" . $_FILES["fileToUpload"]["name"], "../$title/$title.mp4");
  63.  
  64. echo "<div class='success'>The file <a href='/videos/$title/'" . $_FILES["fileToUpload"]["name"] . "'>". basename( $_FILES["fileToUpload"]["name"]). "</a> has been uploaded.</div><br>";
  65. } else {
  66. echo "<div class='error'>There was an error uploading your file.</div><br>";
  67. }
  68. }
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement