1

我想用 webroot 之外的 php(取消链接功能)文件删除。我的网络根在

C:\server\webroot\project\... in webroot I have folder named project and in there I have .php 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-WARNING No such file or directory

我也有(test.php)html表单这个=>

<a href="/mp3/file.txt">Download</a>

这有效(它打开这个file.txt)

所以我想知道为什么不能用标记函数“delete($filename)”删除?

4

3 回答 3

2

“/mp3/”。$filename 是一个绝对文件路径,而不是相对于网络服务器根目录,因此假设您在文件系统根目录下有一个 mp3 目录,而您应该在 /server/mp3 下查看

编辑

它是 /server/mp3 还是 /server/mp3_files

您的帖子似乎与您的代码相矛盾

于 2012-01-04T15:08:24.373 回答
2

PHP 中的文件函数来自文件系统根目录。

你应该写:

function delete($filename){
if (unlink("C:\\server\\mp3_files\\" . $filename)){
    echo "Deleted";
} else {
    echo "No";
}
 }
delete("file.txt");
于 2012-01-04T15:09:17.397 回答
1

为了确保内部 PHP 文件路径缓存获得正确的信息,clearstatcache()请在取消链接之前和之后对其进行重置。通常,路径缓存会在每个与文件操作相关的 PHP 函数之后重置。shell_exec('rm file.txt')如果您删除具有或类似的文件,则需要重置缓存。

请参阅http://php.net/manual/ini.core.php#ini.realpath-cache-sizehttp://php.net/manual/ini.core.php#ini.realpath-cache-ttl

于 2012-01-04T15:14:37.697 回答