php 取消链接文件已更新
我想用 php(取消链接功能)删除 webroot 之外的文件。我的网络根目录位于
C:\server\webroot\project\... in webroot I have folder named project and in there I have .php files.
“whats about files”目录中。它位于 C:\server\mp3_files...
另外,我在 mp3_files 目录的 httpd.conf Alias("mp3") 中创建了
我正在 C:\server\webroot\project\test.php 脚本中编写的脚本
是像这样=>
function delete($filename){
if (unlink("/mp3/" . $filename)){
echo "Deleted";
} else {
echo "No";
}
}
delete("file.txt");
这个脚本给了我 php-errors =>; PHP-警告没有这样的文件或目录
我也有(test.php)html形式这个=>;
<a href="/mp3/file.txt">Download</a>
这有效(它打开这个 file.txt)
所以我想知道为什么不能用标记的函数“delete($filename)”删除?
I want to delete with php (unlink function) file which is out of webroot. my web root is in
C:\server\webroot\project\... in webroot I have folder named project and in there I have .php files.
whats about files directory. it is situated C:\server\mp3_files...
Also I've created in httpd.conf Alias("mp3") of mp3_files directory
I am writing this script in C:\server\webroot\project\test.php
script is like so =>
function delete($filename){
if (unlink("/mp3/" . $filename)){
echo "Deleted";
} else {
echo "No";
}
}
delete("file.txt");
this script gives me in php-errors => PHP-WARNING No such file or directory
also I have in (test.php) html form this =>
<a href="/mp3/file.txt">Download</a>
And this works (It opens this file.txt)
So I'm wondered why can't delete with marked function "delete($filename)" ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“/mp3/”。 $filename 是绝对文件路径,与网络服务器根目录无关,因此当您应该在 /server/mp3 下查找时,假设您的文件系统根目录下有一个 mp3 目录
编辑
是 /server /mp3 或 /server/mp3_files
您的帖子似乎与您的代码相矛盾
"/mp3/" . $filename is an absolute filepath, not relative to the webserver root, so it's assuming that you have an mp3 directory under your filesystem root when you should be looking under /server/mp3
EDIT
And is it /server/mp3 or /server/mp3_files
your post seems to contradict your code
PHP 中的文件函数来自文件系统根目录。
你应该写:
File function in PHP go from the file system root.
You should write:
为了确保内部 PHP 文件路径缓存获取正确的信息,请使用
clearstatcache( )
取消链接之前和之后。通常,在每个与文件操作相关的 PHP 函数之后都会重置路径缓存。如果您使用shell_exec('rm file.txt')
或类似命令删除文件,则需要重置缓存。请参阅http://php.net/manual/ini.core。 php#ini.realpath-cache-size 和 http://php.net/manual/ini.core.php#ini.realpath-cache-ttl
To make sure the internal PHP file path cache gets the correct information, reset with it with
clearstatcache()
before and after the unlink. Normally the path cache is reseted after every PHP function which is related to file manipulation. Reseting the cache is required if you remove files withshell_exec('rm file.txt')
or similar.See http://php.net/manual/ini.core.php#ini.realpath-cache-size and http://php.net/manual/ini.core.php#ini.realpath-cache-ttl