[英]Symfony How To Remove A File
Why cant I use unlink() in Symfony? 为什么我不能在Symfony中使用unlink()?
I have tried this: 我已经试过了:
unlink(/Applications/XAMPP/xamppfiles/htdocs/symfonydev/web/account_assets/data/suppliers/file.txt)
I keep getting the same reponse: Warning: unlink(/Applications/XAMPP/xamppfiles/htdocs/symfonydev/web/account_assets/data/suppliers/wordpress.txt): Permission denied in... 我一直收到相同的响应:警告:取消链接(/Applications/XAMPP/xamppfiles/htdocs/symfonydev/web/account_assets/data/suppliers/wordpress.txt):权限被拒绝...
What Do I need to do??? 我需要做什么???
I have set the permissions to 777 on this file. 我已将此文件的权限设置为777。
Note that you can use the remove function of the filesystem component . 请注意,您可以使用文件系统组件的删除功能。 If you don't want to use the filesystem component, that's fine, you can use
unlink()
, there is a great example in this remove function of the doc : 如果您不想使用文件系统组件,那么可以使用
unlink()
, 在doc的remove函数中有一个很好的例子:
public function removeUpload()
{
if (isset($this->file)) {
unlink($this->file);
}
}
Now, the main problem is that you don't have permission to delete this file. 现在,主要问题是您无权删除此文件。 You'd have to configure the directory like this in your virtual host:
您必须在虚拟主机中配置如下目录:
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/symfonydev/web/"
ServerName yoursite.dev
<Directory "/Applications/XAMPP/xamppfiles/htdocs/symfonydev/web/account_assets/data/">
AllowOverride None
Allow from All
</Directory>
</VirtualHost>
It was a permissions issue on main directory that contained the files. 这是包含文件的主目录上的权限问题。 Once I changed the owner and permissions, all worked well.
更改所有者和权限后,所有功能都可以正常运行。 The filesystem component works awesome!
文件系统组件的功能很棒!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.