Skip to content

Video uploader, trying to show a video player after upload

As the title says im trying to create a url or want to use a script to show my video after the upload. I want to use afterglow as video player, any tip or help would help me out! Here is the code of my upload.php:

<?php
if (isset($_POST['submit'])) {
    $file = $_FILES['file'];

    $fileName = $file['name'];
    $fileTmpName = $file['tmp_name'];
    $fileSize = $file['size'];
    $fileError = $file['error'];
    $fileType = $file['type'];

    $fileExt = explode('.', $fileName);
    $fileActualExt = strtolower(end($fileExt));

    $allowed = array('jpg', 'jpeg', 'png', 'mp4');

    if (in_array($fileActualExt, $allowed)) {
        if ($fileError === 0) {
            if ($fileSize < 10000000000) {
                $fileNameNew = uniqid('', true).".".$fileActualExt;
                $fileDestination ='uploads/'.$fileNameNew;
                move_uploaded_file($fileTmpName, $fileDestination);
                header("Location: index.php?uploadsuccess");
            } else {
                echo "Your file is too big!";
            }
        } else {
            echo "There was an error uploading your file!";
        }
    } else {
        echo "You cannot upload files of this type!";
    }
}

Advertisement

Answer

You need to use HTML to render your video:

<!DOCTYPE html>
<html>
  <head>
    <title>afterglow player</title>
    <script src="//cdn.jsdelivr.net/npm/afterglowplayer@1.x"></script>
  </head>
  <body>
    <video class="afterglow" id="myvideo" width="1280" height="720">
      <source type="video/mp4" src="/path/to/myvideo.mp4" />
    </video>
  </body>
</html>

Make sure to echo the source of the uploaded video like so

src="<?php echo $videolink; ?>"
User contributions licensed under: CC BY-SA
3 People found this is helpful