2013-04-08 60 views
1

你好我已经在这个脚本上工作了两个星期,我不知道该怎么做。
我在PHP工作,我想下载视频,问题在于“读取文件”功能不适用于/ var/www文件,这是一个问题,因为我有很多视频,没有足够的空间/分区。这是我的脚本谢谢。Php readfile('/ home/myhome/video.mp4')

$fichero = "/home/myhome/Video/$video"; 

if (file_exists($fichero)) { 
     header('Content-Description: File Transfer'); 
     header('Content-Type: application/octet-stream'); 
     header('Content-Disposition: attachment; filename='.basename($fichero)); 
     header('Content-Transfer-Encoding: binary'); 
     header('Expires: 0'); 
     header('Cache-Control: must-revalidate'); 
     header('Pragma: public'); 
     header('Content-Length: ' . filesize($fichero)); 
     ob_clean(); 
     flush(); 
     readfile($fichero); 
     exit; 
}else{ 
    die("The File $fichero does not exist"); 
} 

我双重检查的地址,我增加了下载的最大尺寸,所以请,如果您有任何解决方案,这将是巨大的。

+0

它应该对它们起作用。什么是进入你的视频目录的权限?你也可以在你的'www'目录内创建一个'video'目录的链接,并确保所有文件都是全局可读的('+ r')。 – Jon 2013-04-08 15:14:35

+0

那么究竟是什么问题呢? '/ var/www'与脚本中提到的'/ home/myhome/Video'有什么关系? – pilsetnieks 2013-04-08 15:15:25

回答

2

您可以使用国防部重写做到这一点:

http://httpd.apache.org/docs/2.2/urlmapping.html

使用类似:

RewriteEngine On 
Alias /videos /home/myhome/Video 

将在/home/myhome/Video/任何文件映射到www.site.com/videos/

或者你可以更具体一点,并基于正则表达式匹配:

RewriteEngine On 
ScriptAliasMatch ^/videos/([^\.])+.mp4 /home/myhome/Video/$1.mp4 

将其映射其规则匹配的任何文件:/videos/everythingexepctadot.mp4和IT这与一些的RewriteCond的映射到/home/myhome/Video/matchedtext.mp4

夫妇和你有youself非Web根目录服务备份数据的简单方法。

+0

它几乎工作,但我有问题的权限。我将它们改为777,但仍然出现403错误。 – 2013-04-18 20:01:02

0



请先检查目录的读写权限。只需在代码下面尝试动态设置权限即可。

chmod("/home/myhome/Video/", 0644); 

$fichero = "/home/myhome/Video/$video"; 

if (file_exists($fichero)) { 
//Your Code 
}else{ 
//Your Code 
} 

干杯,
简森。