Examples of using filesystem file system functions in PHP

Source: Internet
Author: User
Tags chmod html tags http post php example symlink

  This article mainly introduces the use of filesystem file system functions in PHP example, the need for friends can refer to the following

basename-returns the filename part of the path dirname-the directory part of the return path     code is as follows: String basename (String $path [, String $suffix]) Strin G DirName (String $path)     Example:     code is as follows: <?php $path = "/home/httpd/phpha.com/index.php"; Echo basename ($path); Echo basename ($path, '. php '); Echo basename ($path, '. xxx '); echo dirname ($path);?>     code is as follows://Results: index.php index index.php/home/httpd/phpha.com     NOTE: if the filename Is ended with the right suffix, and that part will be removed.   chgrp-Change the chown-file owner chmod-Change the file mode   code as follows: BOOL chmod (string $filename, int $mode)   &N Bsp Example:     code is as follows: <?php chmod ('/home/phpha.txt ', 0755);?> copy-Copy file   if (copy (' index.php ', ' index.php.b Ak ') { echo ' copy success ';}?>//Live in the current directory Index.php.bak files       delete-See unlink or unset Unlin The K-Deletion file code is as follows: <?php if (unlink (' Index.php.bak ')) { echo ' unlink success ';}?>//deleted Index.php.bak     disk_free_space-returns the available space in the directory Disk_total_space-returns the total disk size of a directory diskfreespace-disk_free_space alias     code is as follows: <?php//Under Windows: Echo Disk_free_spac E ("C:"), ' <br/> '; Echo Disk_total_space ("C:");?> code is as follows://Result: Returns the number of bytes 17433419776 32218386432     fopen-open file or URL fgets-from file Read a row in the pointer feof-the test file pointer to the end of the file fread-read the file (safe for binary) fwrite-write to file (safe for binary files) fclose-close an open file pointer     code such as Under: <?php $fp = fopen (' hello.txt ', ' R '); Open a file $n = 1; while (!feof ($fp)) { echo $n, '-', fgets ($fp), ' <br/> ';//read one line and output   $n + +;} fclose ($FP); Close file?>     code is as follows://output: 1-welcome to my blog:2-http://www.jb51.net     fgetc-read characters from file pointer fge Tcsv-reads a row from the file pointer and resolves the CSV field fgetss-reads a row from the file pointer and filters out the HTML tags fputcsv-the alias   code for the row to be formatted as CSV and written to the file pointer fputs-fwrite: & lt;? PHP $fp = fopen (' hello.txt ', ' R '); while (false!== ($char = fgetc ($fp))) {    echo $char, '-';}?>       code as follows://output: w-e-l-c-o-m- E--t-o--m-y--b-l-o-g-:---h-t-t-p-:-/-/-b-l-o-g-.-p-h-p-h-a-.-c-o-m-    file_exists-Check the existence of files or directories     copy code code as follows: <?php if (file_exis TS (' Hello.txt ')) { echo ' hello.txt exists ';} else{ echo ' hello.txt not exists ';?>   [/code]//output: Hello.txt exists [/code]   file_get_contents- Read the entire file into a string file_put_contents-writes a string to the file file-reads the entire file into an array   code as follows: <?php if ($content = file_get_contents (' Hel Lo.txt ')) { file_put_contents (' Hello.txt.bak ', $content);}?>//is equivalent to copy a copy of Hello.txt <?php if ($content = File (' Hello.txt ') { print_r ($content);}?>//array form, each row is an array member array (    [0] => Welcome to my blog:     [1] => http://www.jb51.net)     fileatime-get file Last access time filectime-the Inode modification time of the file Filegrou P-Obtain the file group fileinode-obtain the file's Inode filemtime-Obtain the file modification time fileowner-obtains the file the owner fileperms-obtains the file the permission filesize-obtains the file size Filetyp E-Get file type     code as follows: <?php echo fileatime (' hello.txt '); echo filectime (' hello.txt '); Echo FIlegroup (' Hello.txt '); echo filemtime (' hello.txt '); echo fileowner (' hello.txt '); Echo substr (sprintf ('%o ', fileperms (' Hello.txt ')),-4); echo filesize (' hello.txt '); echo filetype (' hello.txt ');?>       Replication code code is as follows://output: 1353329003 1353329003 0 1353330002 0 0666 file     flock-Lightweight consultation file locking fnmatch-a pattern matching file name fflush-outputting the buffered content to the file fpassthru-all remaining data at the output file pointer fscanf-format input from the file fseek -Locate fstat-in the file pointer to obtain file information through an open file pointer ftell-returns the location of the file pointer read/write ftruncate-truncates the file to a given length glob-looking for a file path   is_dir-judgment given with pattern matching Whether the file name is a directory is_executable-determine whether a given file name can be executed is_file-determine whether a given file name is a normal file is_link-determine whether a given file name is a symbolic connection is_readable-determine whether a given filename is readable I s_uploaded_file-determine if the file is a is_writable-of HTTP POST uploads to determine if a given filename is writable is_writeable-is_writable alias Description: The above functions are used to determine whether a file or directory is compliant Returns TRUE or FALSE for the corresponding condition.   Lchgrp-changes group Ownership of Symlink lchown-changes user ownership of Symlink link-establish a hard connection linkinfo-get A connected information lstat-gives information about a file or symbolic connection mkdir-new directory move_uploaded_file-move uploaded files to a new location parse_ini_file-resolves a profile pathinfo-returns information about a file path pclose-closes the process file pointer popen-opens the process file pointer readfile-outputs a file readlink-returns a symbolic connection to the target real path-returns the normalized absolute pathname rename-renames a file or directory rewind-the location of the file pointer rmdir-deletes the alias Set_file_buffer-stream_set_write_buffer of the directory stat -Give the information of the file symlink-establish a symbolic connection tempnam-create a file with a unique file name tmpfile-create a temporary file touch-set file access and modification time umask-change the current umask CLEARSTATC ache-Erase file state cache  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.