Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- function rrmdir($dir) {
- if (is_dir($dir)) {
- $files = scandir($dir);
- foreach ($files as $file)
- if ($file != "." && $file != "..") rrmdir("$dir/$file");
- rmdir($dir);
- }
- else if (file_exists($dir)) unlink($dir);
- }
- function rcopy($src, $dst) {
- if (file_exists ( $dst ))
- rrmdir ( $dst );
- if (is_dir ( $src )) {
- mkdir ( $dst );
- $files = scandir ( $src );
- foreach ( $files as $file )
- if ($file != "." && $file != "..")
- rcopy ( "$src/$file", "$dst/$file" );
- } else if (file_exists ( $src ))
- copy ( $src, $dst );
- }
- if (!isset($_SESSION['username'])) {
- die("You are not logged in.");
- }
- if ($_POST) {
- $title = $_POST['title'];
- mkdir("../videos/$title");
- $target_dir = "../videos/$title/";
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- echo $target_file;
- echo "<br>" . $_FILES["fileToUpload"]["name"];
- $uploadOk = 1;
- $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
- if (file_exists($target_file)) {
- echo "<div class='error'>File already exists.</div><br>";
- $uploadOk = 0;
- }
- // Check file size
- if ($_FILES["fileToUpload"]["size"] > 5000000) {
- echo "<div class='error'>File is too big!</div><br>";
- $uploadOk = 0;
- }
- // Allow certain file formats
- if($imageFileType != "mp4") {
- echo "<div class='error'>Only MP4 files are allowed.</div><br>";
- $uploadOk = 0;
- }
- // Check if $uploadOk is set to 0 by an error
- if ($uploadOk == 0) {
- echo "<div class='error'>Unknown Error.</div><br>";
- // if everything is ok, try to upload file
- } else {
- if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
- rename ("../$title/" . $_FILES["fileToUpload"]["name"], "../$title/$title.mp4");
- echo "<div class='success'>The file <a href='/videos/$title/'" . $_FILES["fileToUpload"]["name"] . "'>". basename( $_FILES["fileToUpload"]["name"]). "</a> has been uploaded.</div><br>";
- } else {
- echo "<div class='error'>There was an error uploading your file.</div><br>";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement