In PHP, you can use the if statement and the unlink() function to determine whether the file is successfully deleted. The syntax is "if(unlink($file)){echo 'File deleted successfully!';}else{echo ' File deletion failed!';}".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, if you want to delete files, you need Use the unlink() function.
The unlink() function can delete the specified file. It returns TRUE when the function is executed successfully (the file is deleted successfully), and FALSE when it fails.
If you want to determine whether the file is deleted successfully, you can use the if statement. If the unlink() function returns TRUE, it will output a prompt that the file was successfully deleted; if it returns FALSE, it will output a prompt that the file failed to be deleted.
Implementation code:
<?php header("Content-type:text/html;charset=utf-8"); $file = 'newtest.txt'; if (file_exists($file)) { if (unlink($file)) { echo '文件删除成功!'; } else { echo ' 文件删除失败!'; } } else { echo $file . ' 不存在!'; } ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether file deletion is successful in php. For more information, please follow other related articles on the PHP Chinese website!