Batch processing and File system: File system processing in PHP

Source: Internet
Author: User
Tags array bool end file system file upload key resource string

Open file, process file, close file
1 Open, close the file
Is_file ($filename)
Resource fopen ($filename, $mode [, Use_include_path)
$filename: Can be an absolute path or a relative path
$mode is open mode, read and write ... Wait
The third is whether to open the file under this path of the server.
Close File
BOOL Fclose (resource handle);
Sample
$f = fopen ("A.txt", "RB");
Fclose ($f)
2. Read and Write files
int ReadFile ($FILENAME) reads the entire file write to the output buffer, does not need to open the file, does not need echo,print.
Array file ($filename) reads the contents of the entire file and is stored in rows to an array.
File_get_contents ($filename,) reads a file into a string
Read one line:
Fgets ($resource) read one row at a time. If a newline character is encountered, EOF reads to the specified length and ends.
FGETSS ($resource, $length) A variant of the above function that filters out html,php tags
Read a character
Fgetc ($resource)
Determine if the end of the file place
while (!feof ($resource))
Fread ($resource, length) reads the specified length of data.
Writing data to a file
Fwrite ($resource, $string, length)
File_put_contents ($filename, $string)
Other file Actions
BOOL Copy ($path 1, $path 2)
BOOL Rename ($filename 1, $filename 2)
BOOL Unlink ($filename) deleting files
Array PathInfo ($FILENAME)
Realpath ($filename) Absolute path

Directory functions, Directory operations
If you open a file that does not exist, a new file is created and an error occurs if you open a non-existent amount.
Open, close directory
Resource Opendir ($path)
@opendir ($path) Suppress error output
Closedir ($resource) closes the directory.
Is_dir () First Judge $path to open again.
Browse Catalog Scandir
Array Scandir ($path)
Directory Operations
BOOL MkDir ($path) Create a new specified directory
BOOL RmDir ($dirname) deletes a directory that the directory must make empty
String getcwd () get current working directory
BOOL ChDir () Change the current directory to.
Advanced Applications
fopen ("http://127.0.0.1/tm/sl/index.php") Open the remote file ... PHP Configuration Allow_url_fopen on
File pointers:
BOOL Rewind ($resource) point the file pointer to the beginning
Fseek ($resource, $offset, $model) Locate the file pointer
BOOL Feof ($resource) determines whether at the end of the file
Ftell ($resource) quote the position of the pointer
Lock file Flock ($resource, $model)
File Upload
Phpini settings,
1 whether to allow uploading files file_uploads on off
2upload_tmp_dir upload files to the temporary directory
3:upload_max_filesize server allows maximum MB to be uploaded
Predefined variable #$_files
Array first-level key named name, second-level key name Name,size,tmp_name (Move_upload_file ($sourcefile, $ destination)), Type,error (0 for success)
Multiple file uploads, name= "name[]"
This article links http://www.cxybl.com/html/wlbc/Php/20130608/38519.html

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.