Strange problem with readfile, not working

Hi friends

I have this following code which is not working, and was wondering what could be the reason.

$mime_type = mime_content_type($file);	
header('Content-Type: '.$mime_type);
readfile($file);

Here; $file = /var/www/domain.com/upload/monfilm.mp4 (this is outside of the public doman, but the file exists as I can see that in the ftp and can also download via ftp and play using my vlc player)
$mime_type returns video/mp4 showing also that mime type can be read and hence the file is present.
However, if I load the script, I have a black screen with a play button.

if I send the webm version, ie, $file = /var/www/domain.com/upload/monfilm.webm and mime type as application/octet-stream, the php file itself gets downloaded.

Both tests are done in Chrome. Any help will be appreciated, not understanding what is going wrong.

Step 1: Comment out header. Refresh page. Verify content (via View Source) looks like it should (Make sure PHP isnt throwing a warning in, and that the content looks like it should as if you’d opened it in a text editor)
Step 2: Return header, comment out readfile. Verify content (via View Source) is blank. (Again, making sure PHP isnt throwing warnings).

Thanks for your reply Starlion. I tried both, but could not see the source of either file because :smile:

  1. Commenting out header, I am getting the content in the browser as if they would appear in a text editor but the page is loading since an hour now.

  2. Returning header and commenting out readfile, I am getting the black screen on the full page, and the page source cannot be seen as I cannot right click.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.