简单的PHP锁文件函数


Simple PHP lock file function

谁能帮助PHP锁文件功能?

我想创建一个符号链接时,像这样的URL(与文件名是后面的字符"file="):

http://www.blah.com/download.php?file=zFZpj4b2AkEFz%2B3O

,然后我需要拒绝访问,如果符号链接存在…但这不是我的专长!

非常感谢。

您可以使用chmod执行shell脚本来限制访问。在php中使用exec函数

ln -s mysymlink
if [  -f mysymlink ] then
    chmod 000 filenametobedenied
fi 

这可以是shell脚本,将其保存在文档根目录下,作为filecheck.sh,并通过exec('filecheck.sh')函数运行该脚本

请看这个例子(我的注释)摘自PHP Manual for is_link():

<?php
$link = 'uploads';
if (is_link($link)) { // check if the link exists
    echo(readlink($link)); // echo out path this link points to
    // this is where you ban access
} else {
    symlink('uploads.php', $link); // create the symlink
}
?>
ln -s mysymlink
if [  -f mysymlink ] then
    chmod 000 filenametobedenied
fi 

这可以是shell脚本,将其保存在文档根目录下,作为filecheck.sh,并通过exec('filecheck.sh')函数运行该脚本