"No such file or directory" error when using unlink() despite file_exists() returning true

70 Views Asked by At

I'm encountering an issue while attempting to delete a file using the unlink() function in PHP. Strangely, the file_exists() function returns true for the file path, indicating that the file does indeed exist. However, when I try to delete the file using unlink(), I'm getting an error message saying "No such file or directory."

Here's a snippet of my code:

$file_path = 'shooping/cloths.png';

if (file_exists($file_path)) {
    if (unlink($file_path)) {
        echo "File deleted successfully.";
    } else {
        echo "Error deleting file.";
    }
} else {
    echo "File does not exist.";
}

I've double-checked the file path, and it seems to be correct. The file has read and write permissions, and I'm running this code in a web server environment. What could be causing this issue? Is there anything else I should be looking into to troubleshoot this problem? I am new to php

0

There are 0 best solutions below