Home >Backend Development >PHP Problem >What to do if the php unlink function reports an error

What to do if the php unlink function reports an error

青灯夜游
青灯夜游Original
2021-09-17 18:29:162705browse

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.

What to do if the php unlink function reports an error

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 = &#39;C:\Users\Administrator\Desktop\cut.jpg&#39;;
unlink($to_link);
?>

What to do if the php unlink function reports an error

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 = &#39;C:\Users\Administrator\Desktop\cut.jpg&#39;;
@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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn