Home >Backend Development >PHP Problem >What is the function to delete pictures in php

What is the function to delete pictures in php

青灯夜游
青灯夜游Original
2021-09-02 15:09:102172browse

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.

What is the function to delete pictures in php

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 = &#39;./img/What is the function to delete pictures in php&#39;;
if(file_exists($file)){
    if(unlink($file)){
        echo $file.&#39; 删除成功!&#39;;
    }else{
        echo $file.&#39; 删除失败!&#39;;
    }
}else{
    echo $file.&#39; 不存在!&#39;;
}
?>

Output result:

What is the function to delete pictures in php

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!

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