简体   繁体   中英

Symfony How To Remove A File

Why cant I use unlink() in Symfony?

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...

What Do I need to do???

I have set the permissions to 777 on this file.

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 :

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM