In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to delete local files with php". In daily operation, I believe many people have doubts about how to delete local files with php. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to delete local files with php". Next, please follow the editor to study!
Use php to delete local files: 1, create a new php file and set the code to utf8;2, create two variables, which are used to save the directory name of the deleted file and the file name that needs to be deleted; 3, use the file_exists () method to determine whether the directory exists; 4, use the unlink () method to delete the file.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How to delete local files with php?
Delete a file specified in a directory with PHP:
Create a new php file, named test.php, to explain how to use PHP to delete a file specified in a directory.
In the test.php file, use the header () method to set the encoding executed by the file to utf8 to avoid garbled when the page is output in Chinese. The code is as follows:
Within the test.php file, create two variables, one is the $path variable to hold the directory name of the deleted file, and the other is the $filename variable to hold the file name you want to delete.
In the test.php file, use the file_exists () method to determine whether the directory exists, and if the directory exists, execute the program statements in the if.
Within the test.php file, connect the $path directory with the $filename file name to the path to delete the file, and use the unlink () method to delete the file specified in this path.
In the test.php file, judge the deletion result after unlink () executes the deletion through the if statement. If it is returned as true, the output "delete the file successfully!" If returned as false, the output "failed to delete file!" .
Run the test.php file in the browser to see the output after executing the program.
At this point, the study on "how to delete local files with php" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.