0

I have a site where the main idea is .webms playing and every time you click a button it loads the next .webm at random but I would like to somehow give each webm its own unique URL kind of like (website.com/WEBM-NAME-HERE). I have unique names for all the webm files and would like to also hide the file extenstion in the URL somehow.

Here is what I am currently working with for random webms:

function random_vid($dir = 'storage')
{
 $files = glob($dir . '/*.*');
 $file = array_rand($files);
 return $files[$file];
}

and then in my html I have it give me a random video like this:

<?php include('randomizevid.php');?>
<video autoplay loop>
<source src="<?php echo random_vid(); ?>" type='video/webm'>
</video>

Any help getting those unique URLs is greatly appreciated. I just want it to be so if you share a URL with someone it takes them to the same webm.

1 Answers1

0

If you have a file on your server, user can download it using a direct uri which coincides with file's path in server's file system.

If you want to use an uri that does not coincide file's path, you have two ways:

Set especial rules for your web server. Example for nginx:

location ~ ^/storage/(.+)$ {
    try_files /storage/$1.webm =404;
}

Or handle all requests with your php script. Please see example. You need a script, which get an id, or some kind of hash that will be tranformable to file's path. Also read about limitations of file handling with php.

marv255
  • 808
  • 6
  • 19