Home >Backend Development >PHP Problem >How to delete files in php

How to delete files in php

王林
王林Original
2020-08-06 15:11:096481browse

How to delete files in php: You can use the unlink() function to delete files. If the deletion is successful, this function returns true; if the deletion fails, it returns false. The specific usage method is: [if (!unlink($file)){false}else{true}].

How to delete files in php

#unlink() function deletes files. If successful, the function returns TRUE. On failure, returns FALSE.

(Recommended tutorial: php graphic tutorial)

Syntax:

unlink(filename,context)

Parameters:

  • filename Required. Specifies the files to be deleted.

  • #context Optional. Specifies the environment for a file handle. context is a set of options that can modify the behavior of the stream.

(Video tutorial recommendation: Introduction to Programming)

Code implementation:

<?php
/**
 * [$file 文件删除执行]
 * @var string
 */
$file = "test.txt";
if (!unlink($file))
  {
  echo ("Error deleting $file");
  }
else
  {
  echo ("删除成功 $file");
  }
?>

The above is the detailed content of How to delete files 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