Masiar Masiar - 1 year ago 96
PHP Question

PHP does unlink function works with a path?

I would like to remove a file from a folder in PHP, but I just have the path to this file, would it be ok to give the path to unlink? For example


If this doesn't work, the only way to get rid of those files would be to create a .php file in the path/to/ directory and include it somehow in my file an call a method there to remove the file, right?

Answer Source

Have a look at the unlink documentation:

bool unlink ( string $filename [, resource $context ] )


Path to the file.

So it only takes a string as filename.

Make sure the file is reachable with the path from the location you execute the script. This is not a problem with absolute paths, but you might have one with relative paths.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download