Php读取文件(';/home/myhome/video.mp4';)
您好,我已经为这个脚本工作了两周,但我不知道怎么做。Php读取文件(';/home/myhome/video.mp4';),php,file,file-upload,Php,File,File Upload,您好,我已经为这个脚本工作了两周,但我不知道怎么做。 我在PHP中工作,我想下载视频,问题是“readfile”函数不能处理/var/www以外的文件,这是一个问题,因为我有很多视频,而/partition中没有足够的空间。这是我的剧本,谢谢 $fichero = "/home/myhome/Video/$video"; if (file_exists($fichero)) { header('Content-Description: File Transfer');
我在PHP中工作,我想下载视频,问题是“readfile”函数不能处理/var/www以外的文件,这是一个问题,因为我有很多视频,而/partition中没有足够的空间。这是我的剧本,谢谢
$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");
}
我仔细检查了地址并增加了最大下载量,因此如果您有任何解决方案,那就太好了。您可以使用mod rewrite来完成此操作: 使用类似于:
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/everythingexecpctadot.mp4
,并将其映射到/home/myhome/Video/matchedtext.mp4
再加上一些RewriteCond,您就有了一种从非web根目录提供数据的简单方法。
请先检查目录读/写权限。请尝试下面的代码来动态设置权限
chmod("/home/myhome/Video/", 0644);
$fichero = "/home/myhome/Video/$video";
if (file_exists($fichero)) {
//Your Code
}else{
//Your Code
}
干杯,简森。应该对他们有用。您的视频目录有哪些权限?您还可以从
www
目录中创建指向video
目录的链接,并确保所有文件都是全局可读的(+r
)。那么这里到底是什么问题?脚本中提到的/var/www
与/home/myhome/Video
有什么关系?它几乎起作用了,但我的权限有问题。我把它们改成了777,但我仍然得到了错误403禁止。