Php file operations

Source: Internet
Author: User
Php file operations

  1. // File operations
  2. // Copy () copy the object
  3. // Unlink () delete an object
  4. // Ftruncate () truncates the object to the specified length
  5. // Rename () rename a file or directory
  6. If (copy ("data.txt", "data_bak.txt") {// copy a file instance
  7. Echo "file copied successfully
    ";
  8. } Else {
  9. Echo "file copy failed
    ";
  10. }
  11. If (file_exists ("data_bak.txt") {// delete a file instance
  12. If (unlink ("data_bak.txt ")){
  13. Echo "file deleted successfully
    ";
  14. } Else {
  15. Echo "an error occurred while deleting the file.
    ";
  16. }
  17. } Else {
  18. Echo "the target file does not exist.
    ";
  19. }
  20. If (rename ("file.jpg", "file.txt") {// rename the file instance
  21. Echo "file renamed successfully
    ";
  22. } Else {
  23. An error occurred while renaming the echo file.
    ";
  24. }
  25. $ Fp = fopen ("data_bak.txt", "r +") or die ("file opening failed ");
  26. If (ftruncate ($ fp, 1024 )){
  27. Echo "the file has been intercepted ";
  28. } Else {
  29. Echo "failed to intercept the file ";
  30. }
  31. Fclose ($ fp );
  32. ?>


PHP

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.