PHP deletes uploaded images and folders (example sharing)

WBOY
Release: 2016-07-25 08:55:43
Original
1100 people have browsed it
  1. /**

  2. * Delete uploaded pictures and folders
  3. * by bbs.it-home.org
  4. */
  5. $folder = "D:wwwjbxue\"."testimage";
  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 "picture
    ";
  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. ?>

复制代码

说明: 运行于虚拟空间的话,则可能会由于文件夹的权限问题导致不能删除图片和文件夹。 这里使用了777,可能一般的虚拟空间上的都是660吧,可以改成770,实在不行就改成777吧,安全系数低了些。

>>> 您可能感兴趣的文章: php 删除记录同时删除图片文件的代码 PHP上传图片、删除图片的简单示例代码 PHP删除N分钟前创建的所有文件的小例子 php删除目录及所有文件的方法举例 php删除目录下N天前所有文件的代码一例 php删除记录同时刷新当前页面的实现代码 删除指定文件夹中所有文件的php代码 php上传与删除图片的简单范例 php写的一个删除目录的函数 php递归创建和删除文件夹的代码 php递归删除目录及文件的自定义函数rrmdir php递归删除目录的例子



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template