Search code examples
phpunlink

unlink PHP works when file is in root, not if file is in folder


So this one is pretty straight forward I want to delete a file on the server using PHP, I have:

$myfile = 'theone.png';
unlink($myfile);

This code deletes the file, howevere if the path to file is /images/theone.png, it doesn't work, I have tried images\theone.png with no luck.

If I try and connect with FTP I get the error message to say that cURL does not support the unlink function... Any help would be great.

Thanks Guys!


Solution

  • What about:

    $root = realpath($_SERVER['DOCUMENT_ROOT']);
    $myfile = '$root/images/theone.png';
    unlink($myfile);
    

    Although to my knowledge, your attempted method should work, unless either I'm missing something, or you haven't included some code here that might be interfering with the unlink.