Home > Backend Development > PHP Tutorial > PHP file itself

PHP file itself

WBOY
Release: 2016-07-25 08:42:57
Original
948 people have browsed it
  1. //The operation of the file itself
  2. //copy() copies the file
  3. //unlink() deletes the file
  4. //ftruncate() truncates the file to the specified length
  5. //rename() Rename a file or directory
  6. if(copy("data.txt","data_bak.txt")){//Copy file example
  7. echo "File copied successfully
    ";
  8. }else{
  9. echo " File copy failed
    ";
  10. }
  11. if(file_exists("data_bak.txt")){//Delete file instance
  12. if(unlink("data_bak.txt")){
  13. echo "File deleted successfully
    ";
  14. }else{
  15. echo "File deletion failed
    ";
  16. }
  17. }else{
  18. echo "The target file does not exist
    ";
  19. }
  20. if(rename("file.jpg","file.txt")){//Rename file instance
  21. echo "File rename successful
    ";
  22. }else{
  23. echo "File rename failed
    ";
  24. }
  25. $fp=fopen("data_bak.txt","r+") or die("File opening failed");
  26. if(ftruncate($fp,1024)){
  27. echo "File interception successful";
  28. }else{
  29. echo "File interception failed";
  30. }
  31. fclose($fp);
  32. ?>
Copy code

PHP


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template