Jump to content

Recommended Posts

I have a file in web root called fileserve.php. It basically hands the user a file that is above web root.

<?php
include("config.php"); // just includes session_start and db connection
if ($_SESSION['user']['authed'] == true)
{
session_write_close();
$id 		= $_GET['id'];
$query 		= mysql_query("SELECT filename FROM episodes WHERE id = '$id'");
$row 		= mysql_fetch_array($query);
$filename 	= "../../media/".$row['filename'];

header( 'Content-Description: File Transfer' );
header( 'Content-Type: video/x-m4v' );
header( 'Content-Disposition: attachment; filename='.basename( $filename ) );
header( 'Content-Transfer-Encoding: binary' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Pragma: public' );
header( 'Content-Length: ' . filesize( $filename ) );
ob_clean();
flush();
readfile( $filename );
exit;
}
?>

 

I am trying to fix up the url so it looks like: http://mysite.com/videos/xxxx.m4v

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^videos/([^/]+).m4v fileserve.php?id=$1

 

When I go to http://mysite.com/videos/1.m4v, I get a 404 not found:

The requested URL /mnt/stor2-wc1-dfw1/xxxxx/mysite.com/web/content/fileserve.php was not found on this server.

 

fileserve.php is definitely there so I am not sure what I am doing wrong.

Link to comment
https://forums.phpfreaks.com/topic/229290-getting-a-404/
Share on other sites

also, just nitpicking but the regex should serve your purposes but it could stand to be a bit better.  Instead of matching one or more of anything that's not a forward slash, it should only be matching for what the expected value of id should be.  Examples:

 

only numbers:

RewriteRule ^/videos/([0-9]+)\.m4v fileserve.php?id=$1

 

alphanumeric

RewriteRule ^/videos/([a-zA-z0-9]+)\.m4v fileserve.php?id=$1

 

This is especially important since you aren't validating $_GET['id'] before using it in your sql query (which you should be...).  As of right now your script is vulnerable to sql injection.

Link to comment
https://forums.phpfreaks.com/topic/229290-getting-a-404/#findComment-1181520
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.