PHP Delete uploaded pictures and folders (instance sharing)

Source: Internet
Author: User
Tags php write
  1. /**

  2. * Delete uploaded pictures 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. ?>

Copy Code

Description: If you run in virtual space, you may not be able to delete pictures and folders because of permissions on the folder. Here used 777, perhaps the general virtual space on the 660 bar, can be changed to 770, it is not possible to change to 777, the safety factor is lower.

>>> you may be interested in the article: PHP delete records at the same time delete the image file code PHP upload pictures, Simple example code to delete a picture php delete a small example of all files created n minutes ago php Delete directory and all Files Method Example php delete directory n days before all files code a case PHP delete record simultaneously refresh the current page implementation code delete PHP code for all files in the specified folder a simple example of PHP uploading and deleting a picture PHP Write a delete directory function PHP recursive create and delete folder code PHP recursive delete directory and file custom function rrmdirphp Recursive Delete directory 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.