PHP file Programming (iv)-Copy folder creation of files, etc.

Source: Internet
Author: User
    1. $file _path=iconv ("Utf-8", "gb2312", "C:\\Documents and Settings\\All Users\\Documents\\My pictures\\ example pictures \ \ \ \ \ \ \ \ \ \ \ \ \ \" ");

    2. /* IF (!copy ("C:\\winter.jpg", "d:\\aa.jpg")) {
    3. echo "Error";
    4. }else{
    5. echo "OK";
    6. }
    7. */

    8. Chinese to transcode, otherwise it will be an error

    9. $file _path=iconv ("Utf-8", "gb2312", "C:\\Documents and Settings\\All Users\\Documents\\My pictures\\ example Pictures \\Winter.jpg ");
    10. if (!copy ($file _path, "d:\\baa.jpg")) {
    11. echo "Error";
    12. }else{
    13. echo "OK";
    14. }
    15. ?>

Copy Code

2. Create and delete folders, create files and delete files

  1. /**

  2. * File and folder creation, deletion
  3. *edit bbs.it-home.org
  4. */
  5. Create a folder ***********
  6. /* IF (mkdir ("D:/PWMM")) {
  7. echo "OK";
  8. }else{
  9. echo "Error";
  10. }
  11. */
  12. First determine if the file name exists Is_dir ("D:/PWMM") | | File_exists ("D:/PWMM")
  13. /*
  14. if (!is_dir ("D:/PWMM")) {
  15. if (mkdir ("D:/PWMM")) {

  16. echo "folder creation succeeded";

  17. }else{

  18. echo "Folder creation failed";

  19. }
  20. }else{
  21. echo "folder already exists";
  22. }
  23. */

  24. Create multi-level catalogs ************

  25. /* $path = "D:/PWM/AAA/BBB/CCC";

  26. if (!is_dir ($path)) {

  27. if (mkdir ($path, 0777,true)) {

  28. echo "folder creation succeeded";

  29. }else{

  30. echo "Folder creation failed";

  31. }
  32. }else{
  33. echo "folder already exists";
  34. }
  35. */
  36. Delete Directory
  37. If the directory exists with a file or directory, the deletion is unsuccessful
  38. /* IF (rmdir ("d:/test11")) {
  39. echo "OK";
  40. }else{
  41. echo "Error";
  42. }
  43. */
  44. Create a file
  45. Create Test.txt in the Test2 directory on the D drive
  46. /* $path = "D:/test2/test.txt";
  47. $FP =fopen ($path, "w+");
  48. Fwrite ($FP, "How is You");
  49. Fclose ($FP);
  50. echo "OK";
  51. */

  52. deleting files

  53. $path = "D:/test2/test.txt";
  54. if (Is_file ($path)) {
  55. if (unlink ($path)) {
  56. echo "Delete succeeded";
  57. }else{
  58. echo "Delete Failed";
  59. }
  60. }else{
  61. echo "file does not exist";
  62. }
  63. ?>

Copy Code
  • 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.