Home > Article > Backend Development > What is the function to delete pictures in php
php's function to delete pictures is "unlink()". This function can delete the specified file. It returns TRUE when the function is executed successfully, and FALSE when it fails; the syntax is "unlink($file);", parameter " $file" specifies the path of the image file that needs to be deleted.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Pictures are also a file type, and you want To delete image files we can use the PHP unlink() function.
The unlink() function can delete the specified file. It returns TRUE when the function is successfully executed and FALSE when it fails. The syntax format is as follows:
unlink(string $filename[, resource $context])
Among them, $filename is to be deleted. The file path; $context is an optional parameter that specifies the environment of the file handle. $ontext is a set of options that modify the behavior of the stream.
Example: Delete the What is the function to delete pictures in php file in the img directory
<?php header("Content-type:text/html;charset=utf-8"); $file = './img/What is the function to delete pictures in php'; if(file_exists($file)){ if(unlink($file)){ echo $file.' 删除成功!'; }else{ echo $file.' 删除失败!'; } }else{ echo $file.' 不存在!'; } ?>
Output result:
Recommended learning: "PHP video tutorial"
The above is the detailed content of What is the function to delete pictures in php. For more information, please follow other related articles on the PHP Chinese website!