PHP 文件编程(四)-文件的拷贝 文件夹创建等

WBOY
Libérer: 2016-07-25 08:59:22
original
937 Les gens l'ont consulté
  1. //$file_path=iconv("utf-8","gb2312","C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\完全达到.jpg");

  2. /* if(!copy("C:\\Winter.jpg","D:\\aa.jpg")){
  3. echo "error";
  4. }else{
  5. echo "OK";
  6. }
  7. */
  8. //中文要进行转码,否则就会报错

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

2、文件夹的创建与删除,创建文件与删除文件

  1. /**

  2. * 文件与文件夹的创建、删除
  3. *edit bbs.it-home.org
  4. */
  5. //***********创建文件夹***********
  6. /* if(mkdir("d:/pwmm")){
  7. echo "OK";
  8. }else{
  9. echo "error";
  10. }
  11. */
  12. //先判断文件名是否存在 is_dir("d:/pwmm") ||file_exists("d:/pwmm")
  13. /*
  14. if(!is_dir("d:/pwmm")){
  15. if(mkdir("d:/pwmm")){
  16. echo "文件夹创建成功";

  17. }else{
  18. echo "文件夹创建失败";

  19. }
  20. }else{
  21. echo "文件夹已存在";
  22. }
  23. */
  24. //*********创建多层级目录************

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

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

  28. echo "文件夹创建成功";

  29. }else{
  30. echo "文件夹创建失败";

  31. }
  32. }else{
  33. echo "文件夹已存在";
  34. }
  35. */
  36. //*********删除目录
  37. //如果目录存在文件或者目录,则删除不成功
  38. /* if(rmdir("d:/test11")){
  39. echo "OK";
  40. }else{
  41. echo "error";
  42. }
  43. */
  44. //************创建文件
  45. //在d盘的test2的目录下创建test.txt
  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. //*************删除文件

  53. $path="d:/test2/test.txt";
  54. if(is_file($path)){
  55. if(unlink($path)){
  56. echo "删除成功";
  57. }else{
  58. echo "删除失败";
  59. }
  60. }else{
  61. echo "文件不存在";
  62. }
  63. ?>
复制代码


source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!