What is the function to delete pictures in php

青灯夜游
Release: 2023-03-12 10:16:02
Original
2112 people have browsed it

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])
Copy after login

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;;
}
?>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!