Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9316509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:38:19+00:00 2026-06-19T02:38:19+00:00

I have been developing a website for teachers using cakephp 2.0.3. One requirement is

  • 0

I have been developing a website for teachers using cakephp 2.0.3. One requirement is for the teachers to be able to upload files (images, docs, pdfs and videos) that are only viewable by a students in a given class. I had been using a php fpassthrough to read binary data to the http output stream.

This has worked fine for all the documents except for the video, which won’t be played by the chrome built-in player, vlc firefox plugin or jwplayer, which will be used on the actual web site. If I save the file, however, Windows media player will play the file fine. Playing the file from the cakephp webroot directory also works fine. Here is the file view code:

The controller code, which loads and outputs the file:

//cakephp find used to pull file information from database
$fileName = "/redacted/" . $File['File']['unit_id'] . "/" . $File['File']['id'];
$fp = fopen($fileName, 'rb');

header("Content-Type: " . $File['File']['type']);
header("Content-Length: " . filesize($fileName));

fpassthru($fp);

The layout which is used:

<?php echo $this->fetch('content'); ?>

The jwplayer loading code:

<div style="width: 200px; height: 91px;" id="1">&nbsp;</div>
<script type="text/javascript">
    jwplayer("1").setup({
        file: "/Files/view/1/blah.m4v",
    });
</script>

The view file is empty, as all output is done in the controller. I’ve looked through this site and google but can’t find a reason for the issue or better way to perform this function. I have verified that the headers are correct and that there are no errant line breaks or data before or after. I have also checked that the extension is not required (in the final code block, ‘1’ specifies the file ID, and the file name at the end is a dummy).

My questions, therefor:

  1. Is fpassthru(), readfile() or similar the correct method for php video passthrough?
  2. Is this problem specific to my code, or inherent to cakephp’s handling of MVC? Has anyone successfully implemented such a solution?
  3. Are there any other ‘thinking outside the box’ solutions (using node.js or some other language, .htaccess trickery) that would work better.
  4. I could use a non-cakephp script in the webroot folder, but how would I go about passing user session data? Is this just a dumb idea?

[Edit]
After testing fpassthrough on video files separate from cakephp, I found that the issue is with the video passthrough rather than cakephp. This code was used to test, in the app/webroot directory:

<?php
    $fileName = "/var/www/redacted/files/2/1";
    $fp = fopen($fileName, 'rb');
    header("Content-Type: video/mp4");
    header("Content-Length: 18485");
    fpassthru($fp);
?>

The content type, path, and length were taken from the database entry for that file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:38:20+00:00Added an answer on June 19, 2026 at 2:38 am

    Cake has the functionality you want built in, check out Media Views in the documentation. Note that it’s deprecated in Cake 2.3.0, but since you’re using 2.0, it should work just fine. I tested the following code and had no problem with it playing a sample m4v in jwplayer or the VLC plugin:

    $this->viewClass = 'Media';
    
    $fileName = WWW_ROOT . DS . 'sample_iPod.m4v';
    
    $parts = pathinfo($fileName);
    
    $params = array(
        'id' => $parts['basename'],
        'name' => $parts['filename'], // requires PHP >= 5.2.0
        'extension' => $parts['extension'],
        'download' => false,
        'path' => $parts['dirname'] . DS
    );
    
    $this->set($params);
    

    Note that Cake will automatically output the correct content type/length for you based on the extension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an images slideshow on one page of a website i've been developing
I am developing a website that requires several user types. I have been able
I have been developing a login library for a website using CodeIgniter. The authentication
I'm developing a website(just for fun) and have been using mostly js/jquery to build
I have been developing a book viewing website that takes rather large images (upwards
I recently launched a website I have been developing over the past year -
I'm developing a website for a client of ours and have been having a
I have been developing a website with PHP in which users will subscribe and
I have been developing a nodejs server to provide server-side-events for a new website
I have been developing a website on a 1440*900 resolution monitor..The page has lots

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.