Php_file file operation Simple common functions

Source: Internet
Author: User
Tags string to file

PHP Test files

<?php
Header ("Content-type:text/html;charest=utf-8");
$fileDir = ' upload/file/content.txt ';
Echo ' File path: '. $fileDir. ' <br/> ';
echo ' Path directory |dirname (): '. DirName ($fileDir). ' <br/> ';
echo ' path filename |basename (): '. basename ($fileDir). ' <br/> ';
echo ' File type |filetype (): '. FileType ($fileDir). ' <br/> ';
echo ' File size |filesize (): '. FileSize ($fileDir). ' <br/> ';
Echo ' File modified Time |filemtime (): '. Filemtime ($fileDir). ' <br/> ';

Echo ' <br/> ';
Echo ' absolute path |realpath (): '. Realpath ($fileDir). ' <br/> ';
Echo ' Returns the path information in array form |pathinfo ():<br/> ';
Print_r (PathInfo ($fileDir)); Echo ' <br/> ';
Echo ' <br/> ';

echo ' Copy and rename file |rename (url01,url02): Return '. Copy ($fileDir, './upload/renamecontent.txt '). ' <br/> ';
echo ' Copy file |copy (url01,url02): Return '. Copy ($fileDir, './upload/copycontent.txt '). ' <br/> ';
Echo ' delete file |unlink (URL): return ' [email protected] ('./upload/unlinkcontent.txt '). ' <br/> ';

Echo ' <br/> ';
Echo ' reads the file information in string form |file_get_contents (URL):<br/> ';
Echo file_get_contents ($fileDir). ' <br/> ';
$putContent = ' Hello word! ';
Echo ' writes a string to the file, the file does not exist automatically created, the directory must exist, |file_put_contents (URL,STR) returns the file size: ';
echo file_put_contents ('./upload/file_put_contents.txt ', $putContent). ' <br/> ';
?>

PHP returns results

File path: Upload/file/content.txt
Path directory |dirname (): Upload/file
Path file name |basename (): Content.txt
File Type |filetype (): File
File size |filesize (): 27
File modification Time |filemtime (): 1411488282

Absolute path |realpath ():D: \kuaipan\www\testphp\upload\file\content.txt
Returns the path information as an array |pathinfo ():
Array ([dirname] = upload/file [basename] = content.txt [extension] = txt [filename] = content)

Copy and rename file |rename (url01,url02): return 1
Copy file |copy (URL01,URL02): return 1
Delete file |unlink (URL): return

Read the file information in string form |file_get_contents (URL):
? Hello word! Bad word!!!
Write string to file, file does not exist automatically created, directory must exist, |file_put_contents (URL,STR) return file size: 11

Php_file file operation Simple common functions

Related Article

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.