php 取消链接文件已更新

发布于 2024-12-24 23:40:24 字数 782 浏览 0 评论 0原文

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

樱桃奶球 2024-12-31 23:40:24

“/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

爱,才寂寞 2024-12-31 23:40:24

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

你应该写:

function delete($filename){
if (unlink("C:\\server\\mp3_files\\" . $filename)){
    echo "Deleted";
} else {
    echo "No";
}
 }
delete("file.txt");

File function in PHP go from the file system root.

You should write:

function delete($filename){
if (unlink("C:\\server\\mp3_files\\" . $filename)){
    echo "Deleted";
} else {
    echo "No";
}
 }
delete("file.txt");
国粹 2024-12-31 23:40:24

为了确保内部 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

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 with shell_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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文