this one really puzzles me, if i use the code below in file delete_pic.php, it give me the Warning: unlink(/upload_pic/image.jpg): No such file or directory in /Sites/delete_pic.php
<?php
$filePath = '/upload_pic/image.jpg';
if (unlink($filePath)) {
echo 'File deleted successfully.';
} else {
echo 'Failed to delete the file.';
}
?>
but if I replace with the relative path $filePath = 'upload_pic/image.jpg'; it works, "File deleted successfully."
Both delete_pic.php and upload_pic folder are in root directory. <img src="/upload_pic/image.jpg"> displays correctly.
Can anyone help me understand? thanks a lot.
You can use both absolute or relative paths:
/like this/upload_pic/image.jpgthis is considered an absolute path.upload_pic/image.jpgthis is considered a relative path.