我有一个使用我的控制之外的流媒体服务器流式传输大型视频文件,有时我想删除的视频文件。当文件碰巧被使用流式服务器的人查看时,PHP错误带有“权限被拒绝”。在PHP中,检查文件是否可以被删除
我想尝试删除该文件可以删除或不前检查。我不想真的尝试删除文件,看看是否失败,我想事先检查。
这是我到目前为止的代码:
$file = "video.flv";
$file2 = "newvideoname.flv";
clearstatcache();
if (is_writeable($file)) {
echo "is writeable";
}
else {
echo "is NOT writeable";
}
echo "\n";
$fh = fopen($file, 'a+');
if (!flock($fh, LOCK_EX | LOCK_NB)) {
// file locked, do something else
echo "is locked";
}
else {
echo "not locked!";
}
fclose($fh);
echo "\n";
if (touch($file)) {
echo "modification time has been changed to present time";
}
else {
echo "Sorry, could not change modification time";
}
echo "\n";
rename($file, $file2);
,当我在执行码流video.flv我得到的输出:
is writeable
not locked!
modification time has been changed to present time
PHP Warning: rename(video.flv,newvideoname.flv): Permission denied in ...
有时候我:
is writeable
PHP Warning: fopen(video.flv): failed to open stream: Permission denied ...
PHP Warning: flock() expects parameter 1 to be resource, boolean given
is locked
PHP Warning: fclose(): supplied argument is not a valid stream resource
PHP Warning: touch(): Utime failed: Permission denied
Sorry, could not change modification time
PHP Warning: rename(video.flv,newvideoname.flv): Permission denied ...
所以有时文件不能被PHP锁定,也不能被PHP触摸(),当然重命名也不起作用,但如此一次PHP说“一切都好”,直到重命名命令。重命名命令有从来没有工作随机机会。
我应该怎么做与文件?
那么文件权限呢? –
@KA_lin不是问题,当视频没有被流式传输时,重命名命令完美地起作用 – Tominator
所以问题是什么? –