The reason why the unlink() function reported an error: The specified file to be deleted does not exist. Solution: Add an error suppressor "@" before the unlink() function, and the syntax is "@unlink($filename)". The "@" error suppressor can block some errors and warning messages caused by problems encountered during function execution.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The unlink() function is used to delete the specified file , but if you want to delete a file that does not exist, unlink() will report an error.
<?php $to_link = 'C:\Users\Administrator\Desktop\cut.jpg'; unlink($to_link); ?>
If you want to block the error report of the unlink function, you can use the error suppressor "@" and add an error suppressor "@" before the unlink() function.
<?php $to_link = 'C:\Users\Administrator\Desktop\cut.jpg'; @unlink($to_link); ?>
If you use @unlink()
, no error will be reported.
Explanation: @Error suppressor
@ can shield some errors and warning messages caused by problems encountered during function execution, so that users cannot see the error messages of the program. In addition to a friendlier user interface, this is more important for security, because information such as the path to the error file is blocked.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if the php unlink function reports an error. For more information, please follow other related articles on the PHP Chinese website!