skip to Main Content

for my current project i need a folder that contains videos which should only be seeable for registered users, i know that i can block the access via .htaccess file but at least i dont exactly get what i want..

my currently .htaccess file is like this:

Deny from all 

at the moment im importing the videos/pictures through php which works for accessing them but its really really slow..

here is an example for my pictures:

<img src="data:image/png;base64,<?php echo base64_encode(file_get_contents("directory")) ?>">

and here for my videos:

<img src="data:video/mp4;base64,<?php echo base64_encode(file_get_contents("directory")) ?>">

im sure there is a better way where the page doesnt take forever to load, i also tried a video stream with php but i get another problem there, i cant leave the page anymore or again like before it takes forever to click links or leave.. 🙁

help is much appreciated!

2

Answers


  1. Chosen as BEST ANSWER

    For anyone having the same issue i found a working code in another thread: https://stackoverflow.com/a/47626870/16587767

    the code which also works on mobile devices while still having the skip functionality in the videos is this:

    $file='path/file.mp4';
    
    header('Content-Type: video/mp4'); #Optional if you'll only load it from other pages
    header('Accept-Ranges: bytes');
    header('Content-Length:'.filesize($file));
    
    readfile($file);
    
    

  2. You can do something like <img src="getfile.php?file=foo.mp4"> and:

    $file = validate_file_name_and_path($_GET['file']);
    
    if( user_logged_in() && user_can_access($file) ) {
      // set appropriate headers, eg:
      header('Content-Type: video/mp4');
      readfile($file);
      exit();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search