PHP newbie here. I'm trying to make a simple page where you upload an mp4 file, and that file is automatically displayed on another page. However, I'm having difficulties when changing the src content for the video.
Here's my upload.php
:
<!DOCTYPE html>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
Select video to upload:
<input type="file" name="file" id="file">
<br>
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
<?php
if (isset($_POST)) {
if (isset($_FILES['file'])) {
$file_name = $_FILES['file']['name'];
$file_tmp = $_FILES['file']['tmp_name'];
$file_type = $_FILES['file']['type'];
$file_ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if ($file_ext != "mp4") {
echo "Please select an mp4 file.";
} else {
move_uploaded_file($file_tmp, "./video.mp4");
header("Location: success.php");
}
}
}
?>
And my index.php
within the same directory:
<html>
<body>
<video autoplay loop muted>
<source src="video.mp4" type="video/mp4">
</video>
</body>
</html>
If I upload a mp4, it does display properly on index.php
. However, if I then upload a different mp4, it still displays the first one, despite the content changing (I know this because if I go into the console and click on the src
in the video
tag, it is the second video I uploaded.)
So if a user has index.php
open on their browser, and a new file is added using upload.php
, is it possible to automatically update the content on index.php
without having to refresh the page? I'm not finding any solutions online regarding this, maybe I'm just searching the wrong questions.
I appreciate any and all help, thank you.