Php deletes uploaded images and folders (instance sharing)

Source: Internet
Author: User
Php deletes uploaded images and folders (instance sharing)

  1. /**

  2. * Deleting uploaded images and folders
  3. * By bbs.it-home.org
  4. */
  5. $ Folder = "D: \ www \ jbxue \". "test \ image ";
  6. If (! File_exists ($ folder ))
  7. {
  8. If (! Mkdir ($ folder, 777 ))
  9. {
  10. Echo "mkdir $ folder (mode: 777) error
    ";
  11. }
  12. Else
  13. {
  14. Echo "mkdir $ folder (mode: 777) okay
    ";
  15. }
  16. }

  17. $ Filename = "aaa.jpg ";

  18. $ Filepath = $ folder. "\". $ filename;
  19. If (! File_exists ($ filepath ))
  20. {
  21. Die ("$ filepath not exist
    ");
  22. }
  23. Else
  24. {
  25. Echo"
    ";
  26. Echo"

    Deleting $ filepath ......

    ";
  27. If (! Unlink ($ filepath ))
  28. {
  29. Echo "unlink $ filepath error
    ";
  30. }
  31. Else
  32. {
  33. Echo "unlink $ filepath okay
    ";
  34. If (! Rmdir ($ folder ))
  35. {
  36. Echo "rmdir $ folder error
    ";
  37. }
  38. Else
  39. {
  40. Echo "rmdir $ folder okay
    ";
  41. }
  42. }
  43. }
  44. ?>

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.