Home >Backend Development >PHP Tutorial >Deletion of files through functions Copy Display Whether to enable magic references

Deletion of files through functions Copy Display Whether to enable magic references

WBOY
WBOYOriginal
2016-07-25 09:07:04941browse
Deletion of files through functions Copy Already displayed Whether to enable magic references
  1. /**
  2. 2012-4-12丨Yiyifan Taixi丨
  3. *Customized addslashes function, supports multi-dimensional arrays, supports automatic identification of whether the server has enabled magic references
  4. */
  5. function add_slashes($var){
  6. //First determine whether the server supports magic quotes
  7. if(get_magic_quotes_gpc()==0){
  8. if(is_array ($var)){
  9. //Traverse the array
  10. foreach($var as $key => $value){
  11. $var[$key] = add_slashes($value);
  12. }
  13. return $var;
  14. }
  15. }elseif(is_string($var)){
  16. //Not an array, but a string
  17. return addslashes($var);
  18. }else{
  19. //Already turned on
  20. return $var;
  21. }
  22. }
  23. //copy Function to realize the copy function of files and folders
  24. function dir_copy($src,$dst){
  25. if(is_dir($src)){
  26. if(!file_exists($dst)){
  27. @mkdir($dst,0777 ,true);
  28. }
  29. }
  30. $fp = opendir($src);
  31. while(!false==($fn=readdir($fp))){
  32. if($fn == "." || $ fn == ".."){
  33. continue;
  34. }
  35. $path = $src.DIRECTORY_SEPARATOR.$fn;
  36. if(is_dir($path)){
  37. dis_copy($path,($dst.DIRECTORY_SEPARATOR.$fn ));
  38. }elseif(is_file($path)){
  39. copy($path,($dst.DIRECTORY_SEPARATOR.$fn));
  40. }else{
  41. copy($path,($dst.DIRECTORY_SEPARATOR.$fn) ;
  42. while(!false== ($fn =readdir($fp))){
  43. if($fn=="." || $fn == ".."){
  44. continue;
  45. }
  46. $path = $src.DIRECTORY_SEPARATOR.$fn;
  47. if(is_dir($path)){
  48. delete_dir($path);
  49. }elseif(is_file($path)){
  50. @unlink($path);
  51. }else{
  52. @ unlink($path);
  53. }
  54. }
  55. }
  56. closedir($fp);
  57. @rmdir($src);
  58. }
  59. //msg output returns
  60. function msg($msg){
  61. echo $ msg."
    ";
  62. echo "Return to the previous page";
  63. die;
  64. }
  65. Copy code
Statement:
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