Php deletes uploaded images and folders (instance sharing)
/**
- * Deleting uploaded images and folders
- * By bbs.it-home.org
- */
- $ Folder = "D: \ www \ jbxue \". "test \ image ";
- If (! File_exists ($ folder ))
- {
- If (! Mkdir ($ folder, 777 ))
- {
- Echo "mkdir $ folder (mode: 777) error
";
- }
- Else
- {
- Echo "mkdir $ folder (mode: 777) okay
";
- }
- }
$ Filename = "aaa.jpg ";
- $ Filepath = $ folder. "\". $ filename;
- If (! File_exists ($ filepath ))
- {
- Die ("$ filepath not exist
");
- }
- Else
- {
- Echo"
";
- Echo"
Deleting $ filepath ...... ";
- If (! Unlink ($ filepath ))
- {
- Echo "unlink $ filepath error
";
- }
- Else
- {
- Echo "unlink $ filepath okay
";
- If (! Rmdir ($ folder ))
- {
- Echo "rmdir $ folder error
";
- }
- Else
- {
- Echo "rmdir $ folder okay
";
- }
- }
- }
- ?>
Note: Images and folders cannot be deleted due to folder permissions when running in a virtual space. 777 is used here. Generally, the virtual space is 660. you can change it to 770. if it is not, change it to 777. the security factor is lower. >>> Articles you may be interested in: php code for deleting image files when deleting records PHP code for uploading images, simple example code for deleting images PHP small example code for deleting all files created N minutes ago php example for deleting directories and all files php code example of deleting all files under the Directory N days ago php deletion record while refreshing the current page implementation code delete all files in the specified folder php code php simple example of uploading and deleting images php write a Delete directory function php recursively create and delete folders code php recursively delete directories and file user-defined function rrmdirphp recursively delete directories example |