Use functions to delete and copy files. check whether magic reference is enabled.

Source: Internet
Author: User
Use functions to delete and copy files. check whether magic reference is enabled.
The deletion and copying of files through functions has shown whether magic reference is enabled.

  1. /**
  2. I still have a hard time
  3. * The custom addslashes function supports multi-dimensional arrays and automatically identifies whether the server enables magic reference.
  4. */
  5. Function add_slashes ($ var ){
  6. // First determine whether the server supports magic reference
  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. // It is a string instead of an array.
  17. Return addslashes ($ var );
  18. } Else {
  19. // Enabled
  20. Return $ var;
  21. }
  22. }
  23. // Copy function to copy 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. }
  43. }
  44. Closedir ($ fp );
  45. }
  46. // Delete a function
  47. Function delete_dir ($ src ){
  48. If (is_dir ($ src )){
  49. $ Fp = opendir ($ src );
  50. While (! False = ($ fn = readdir ($ fp ))){
  51. If ($ fn = "." | $ fn = ".."){
  52. Continue;
  53. }
  54. $ Path = $ src. DIRECTORY_SEPARATOR. $ fn;
  55. If (is_dir ($ path )){
  56. Delete_dir ($ path );
  57. } Elseif (is_file ($ path )){
  58. @ Unlink ($ path );
  59. } Else {
  60. @ Unlink ($ path );
  61. }
  62. }
  63. }
  64. Closedir ($ fp );
  65. @ Rmdir ($ src );
  66. }
  67. // Msg output
  68. Function msg ($ msg ){
  69. Echo $ msg ."
    ";
  70. Echo "back to previous page ";
  71. Die;
  72. }

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.