Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP does unlink function works with a path?

Tags:

php

unlink

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

unlink('path/to/file.txt');

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?

like image 410
Masiar Avatar asked Feb 15 '11 16:02

Masiar


1 Answers

Have a look at the unlink documentation:

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

and

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

like image 200
Felix Kling Avatar answered Sep 28 '22 07:09

Felix Kling