Home  >  Article  >  Backend Development  >  PHP file programming (4)-copying files, creating folders, etc.

PHP file programming (4)-copying files, creating folders, etc.

WBOY
WBOYOriginal
2016-07-25 08:59:22937browse
  1. //$file_path=iconv("utf-8","gb2312","C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures \Completely reached.jpg");

  2. /* if(!copy("C:\Winter.jpg","D:\aa.jpg")){
  3. echo "error";
  4. }else{
  5. echo "OK ";
  6. }
  7. */

  8. //Chinese must be transcoded, otherwise an error will be reported

  9. $file_path=iconv("utf-8","gb2312","C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg");
  10. if(!copy($file_path,"D:\baa.jpg")){
  11. echo "error";
  12. }else{
  13. echo "OK";
  14. }
  15. ?>

Copy code

2. Creation and deletion of folders, creation and deletion of files

  1. /**
  2. *Creation and deletion of files and folders
  3. *edit bbs.it-home.org
  4. */
  5. //***********Create folder************
  6. /* if(mkdir("d:/pwmm")){
  7. echo "OK";
  8. }else{
  9. echo "error";
  10. }
  11. */
  12. //First determine whether 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 created successfully";

  17. }else{

  18. echo "Folder creation failed";

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

  24. //*********Create a multi-level directory************

  25. /* $path="D:/pwm/aaa/bbb/ccc" ;

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

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

  28. echo "Folder creation Success";

  29. }else{

  30. echo "File creation failed";

  31. }
  32. }else{
  33. echo "The folder already exists";
  34. }
  35. */
  36. //*********Delete directory
  37. //If there are files or directories in the directory, the deletion will be unsuccessful
  38. /* if(rmdir("d:/test11")){
  39. echo "OK";
  40. }else{
  41. echo "error";
  42. }
  43. */
  44. //************Create file
  45. //Create test.txt in the directory of test2 on drive d
  46. /* $path="d:/test2/test.txt";
  47. $fp=fopen( $path,"w+");
  48. fwrite($fp,"how are you");
  49. fclose($fp);
  50. echo "OK";
  51. */

  52. //****************Delete file

  53. $path="d:/test2/test.txt";
  54. if(is_file($path)){
  55. if( unlink($path)){
  56. echo "Deletion successful";
  57. }else{
  58. echo "Deletion failed";
  59. }
  60. }else{
  61. echo "File does not exist";
  62. }
  63. ?>

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