Php file system

Source: Internet
Author: User
Tags flock
Php file system file? Handle letter?

1. file operations.

Open the file:

? The specified file ?? Return phase? ? If the specified file does not exist, then? Possible? ?? Jian ?? File.

Resource fopen (string filename, string mode [, int use_include_path] [, resource context]);

Filename can be a file name that contains the file path, or a URL provided by a protocol (open a remote file). to avoid the trouble of system switching, use '/' as the path separator.

Mode: sets the file opening methods, including:

R: Read-only mode. the file pointer is located in the file header.

R +: Read-only mode ---- read/write mode. the file pointer is located in the header file. Note that overwriting may occur.

W: Write-only mode. the file pointer is located in the file header. if the file exists, delete the content and rewrite it. otherwise, create the file on your own.

W +: Write-only mode ---- read/write files. the pointer to the read/write file points to the file header. if the file exists, delete the file and rewrite it. otherwise, create the file on your own.

X: write with caution ---- open the file in write mode, and write the file from the file header. if the file exists, false is returned to generate an E_WARNING-level error message.

X +: write with caution --- open the file in read/write mode. if the file exists, false is returned and an error message at the E_WARNING level is generated.

A: append. the file pointer points to the end of the file. if the file exists, append the file directly. otherwise, create the file on your own.

A +: append. the object pointer points to the end of the object. if the object exists, append or read the object directly. otherwise, create the object by yourself.

B: Binary mode. used to connect to other modes. (windows option)

T: used in combination with other modes. (option in windows)

Use the fopen () function with caution, because the file may be deleted accidentally. at the same time, different operating systems have different row ending habits (UNIX: \ n Windows: \ r \ n Macinitosh: \ r ). if the row Terminator is incorrect, a bunch of garbled characters may be output when the file is opened. the preceding steps can be avoided through "'T'" and "'B.

Read files:

String fgetc (resource handle); // returns a character in the file pointed to by handle. if EOF is encountered, false is returned;

String fgets (int handle [, int length]); // gets a line of characters from the position pointed to by the file pointer, and returns a string of up to length-1 bytes .. the file pointer must be valid and point to a file successfully opened by fopen () or fsockopen. length indicates the length of the data to be read. it ends when a line break, EOF, or length is specified. ignore length to read the end of the row.

String fgetss (resource handle [, int length] [, string allowable_tags]); // read a row and filter out html and php tags.

String fread (int handle, int length );//? File? Arbitrary? Degrees ??.,? Can be used? Take two? File. Handle? Pointing to the file? Source, length? Take length? Word? Or an EOF? Stop? Line.

Example:
 

Readfile (), file () and file_get_contents ?.

Int readfile (string filename [, bool use_include_path, resource context]); //? Take one? File ?? To ???, If yes ,? ? The word ??, No? Returns false. Filename file name .?? Use_include_path control: can I search for files in include_path? true? Yes. Use readfile function? Not required? /?? File.

Array file (string filename [, bool use_include_path [, resource context]); //? Whole? File? Rong? Obtained ?? . If yes ??,?? In? All elements are in files ?? ? The line character is in ?; No? Returns false;

String file_get_contents (string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]); // context? 5.0 new? Can be NULL? Ignore. Offset, maxlen? 5.1? . Offset is used ?? File? Start location, maxlen? Set files? ? Degrees .? Method? Used in 2? ? . Yes? File? Rong? To 1? Start of the string? Method. If the operating system? Supported ,?? Use? Storage ing technology ?? ? Performance. ? URL with special characters (such as space), then? Use urlencode ()?? Line URL ??.

?? : Readfile (), file () and file_get_contents () are in? Integer? File? In? Rong ?, Do you need to use fopen () and fclose ?, But in? Take one? Character, one line and any? ?? Required? .

2 .? Input file:

Int fwrite (resource handle, string [, int length]); //? ? Input operation, it? Yes ?? Fputs ().? The method is used to set the string? Rong? Input file description? Handle ?. If? Set length, then ?? Input length? Word? Or complete the string? What is the operation? Stop. Success? Incoming? Returns true, no? Returns false.

?? : Ru? Output length ??, So? Magic_quotes_runtime ???? Ignored, while oblique in string ?? No? Extracted .? Score two? ?? Playing? File? Fopen () letter? Mode ?? Add 'B '.

Int file_put_contents (string filename, string data [. int flags [, resource context]); //? I? String? In the file, if yes? Return word ??, No? Returns false. Flags :??? File? Set (?? There are file_use_include_path, file_append: append, lock_ex :??? ). Context 1? Context? Source.

?? : Fwrite ()? Actually ?? The file entry function, but required? Are there fopen () and fclose () letters? . File_put_contents () integrates the fopen (), fwrite (), and fclose () functions. can you ?? Completed File? .

3 .?? File

File hitting? ?? Yes ?? Function ,? File operations? End ,?????? File, no? It may cause ??.

Bool fclose (resouce handle );//??? The file to which handle points ??, If yes? Returns true, no? Returns false.

? Fixed file

In Xiangyi? In a text file? Inbound ?? ? What should I do first? Fixed file. how can this problem be avoided? Same? Also modify this file? . In php? Flock () letter ??? File? Yes.

Bool flock (int handle, int operation );//?? Operation Control? OK? Limits. Including: lock_sh: share? Set (? Program ). Lock_ex: get ??? Set (? ). Lock_un :? Put? Yes. Lock_nb: prevent flock () function? In? OK? Blocked.

Why ?? Handle letter?

Object? Yes? Special file. Since it is a file, if? Which? Row operation, same? Required? Hit first ?, Then? OK ?? Operation, last? Yes? Yes ??.

1. playing? Object?

? Specified object? File. if it succeeds ,? Returned object? . No? Returns false .? ? What is different about files? Does not exist, it? No? ?? Project creation ?, But? Output 1 ??? Information. ? In opendir? Add the "@" character before ?, Can block ?? Information? Output.

Resource opendir (string path [, resource context]); // specifies the path to be typed? ? File. If path does not specify? Valid object ?, Or because ?? Limit ??, File system ??? Cannot play ?, Then ?? Letter ??? Returns false ,? And? Why? E_WARNING ?? ?? Information.

2 .?? Object?

Use opendir function? The returned handle matches the scandir function ????? Operation.

Array scandir (string directory [, int sorting_ordering [, resource context]); // used ?? Path? Under? And files. If yes? Returns the array containing the file name. no? Returns false. Directory to specify ?? ?, If not ?, Then ?? Returns false ,? And? Why? E_WARNING ?? ?? Information. Sorting_order? Placement? Sequence, Mo ?? Sort letters in ascending order. If? Upper ???,??? Sort in descending order.

?? : Is_dir () letter ?, Sentence? Whether the file name is one? Object ?. If the file name exists and? Object ?,? Returns true, no? Returns false. If it is a phase? Object ?,? By? Previous job objectives ?? Check its phase? ?.

3 .?? Object ?.

Void closedir (resource handle); // handle, yes ?? ? .

?? : Above? As you know, what should I do? ? Does not exist, department ?? No ?? Me ?? Project ?. So? Me? You can do it yourself? Create the desired object ?. Yes? Use the following letter? :

Mkdir? : Create? Object ?, Success? Returns true, no? False.

Rmdir? :? Division ?. Object? Required ?? Empty? Medium? File or sub-object ?), What should I do? Limits.

Unlink () letter? :? Division of files, successful? Returns true, missing? Returns false.

File? , Bottom? Principle

Step ?? Rong:

Step? 1: On control? File, pass? Php. ini file configuration.

Step? 2 :? Upper? File? OK ?. Upper? File size and format.

Step? 3 :? On the line? File operation method.

1. control? File:

Php connectivity ?? Php. ini? Upper? File? Row control, including: is it supported? Upper? File ?? Object? Upper? File size, command? Row ??? Command assigned? Empty ?.

Locate file uploads in the php. ini file ??, Finished? Above ?? ? .?? Include? As follows:

File_uploads: if it is on ,? Tomorrow? File support ?, If? Off ,? Not supported. Generally Mo? Yes. here ?? Do not modify.

Upload_tem_dir: Upper? File ?? Object ?. On the file? Before success, the file is saved to the server first? ?? Object? . More? System used? Mo? Object ?, But you can also do it yourself? .

Upload_max_filesize: server? ? Upper? Maximum file size, in MB ?? Bit. System? Mo ?? 2 MB. if it exceeds ??? Modify its value.

Max_execution_time: one in php? What can I do with commands? The Row's most ???,? The bit is second .? Command in? On the line? Large Files? Required? Modify, no? And? Upper? The file is in the server? ? ???, But super? What can I do with commands? The Row's most ???, Still? Method ?? ?.

Memory_limit: php Zhongyi? Which of the following commands is assigned? Empty ?,? ? MB. It is of the same size ?? Movie? To a large file ?.

?? : In the customer? On the console? File? Used? Form table? Enctype and method? And? MAX_FILE_SIZE.

Enctype = "multipart/form-data": specifies the table ????? Method.

Method = "post": specify ???? .

    : Communication ?? Control the Tibetan domain? File size ,? ? ?.? The value cannot exceed? Upload_max_filesize ??? Value. Cannot it be fully controlled? The file size, can only avoid unnecessary trouble ?.

2. sentence? Upper? File

? Upper? File? OK ?? Is global used? $ _ FILES, $ _ FILES is one ???, It contains all upper? File information .?? ? Element? As follows:

$ _ FILES [filename] [name]: save? Upper? The name of the file, such as text.txt and title.jpg.

$ _ FILES [filename] [size]: save? File size ,? ? Word ?.

$ _ FILES [filename] [tem_name]: save? File in ?? Object? The file name used in, because? File on ?? First? It takes ?? File identity storage? At ?? Object? .

$ _ FILES [filename] [type]: save? Upper? File MIME? Type. MIME? What's the difference? File format? Type, per? MIME? All types? Master separated? Type and sub? Type? . For example, "image/gif" master? Type ?? Like, child? Type? GIF files. "Text/html" indicates the HTML file of the text.

$ _ FILES [filename] [error]: save? File? ?? Generation? : Here? Object? Added in PHP4.2.0? . Its return value is composed of 5? :

0: represents? There are any ??. File? Successful.

1: indicates upper? The file size exceeds the configuration file command upload_max_filesize ?? .

2: indicates upper? The file size exceeds the HTML table? Max_file_size ?? The specified value.

3: indicates that the file is only mounted? .

4: represents? Upper? Any file.

Example:
 0) {echo? File name? : ". $ _ FILES ['up _ picture '] [name]."
"; Echo" on? File? Type: ". $ type ."
"; Echo" on? File size: ". $ _ FILES ['up _ picture '] [size]."
";} Else echo "? The part size does not meet the requirements. ";}}?>

3. file ?.

In php? Use move_uploaded_file () to send a letter ??? File ?. But in? Before the line ,? ? Attack ?? Why can't I connect ?? Interactive file? Illegal row management. can this problem be solved first? Use is_uploaded_file? Sentence? Is the specified file accessible? On http post? If yes? Returns true. ?? Letter ?, Yes? Warranty? Intended use ?? France ?? Ben go ?? No ?? .

Bool is_uploaded_file (string name); // used for determination? Is the specified file accessible? On http post? . Filename required ?? Like $ _ FILES ['filename'] ['temp _ name? Quantity, not available? Customer? Terminal? File name $ _ FILES ['filename'] ['name'].

Move_upload_file (string filename, string destination );//? Letter? Used? File? To the server? The location specified in. If yes ,? Returns true, no? Returns false. Filename: Upper? File ?? File name, that is, $ _ FILES ['tmp _ name'],? Destination specifies the file? What is the new path saved later? And name ?. If ?? Not legal? File, no? Outbound? Any operation ,? Letter ?? Returns false. If it is legal? Operation, but for some reason? Legal shift ?,? No? Outbound? For any operation, the return value of false is the same ???? Output 1? Warning.

 0) {echo ???! "; Switch ($ _ FILES ['up _ picture '] ['error']) {case 1: echo" on? The file exceeds the configuration file? Set value "; break; case 2: echo" on? File exceeds table ?? Set value "; break; case 3: echo" on? Incomplete files "; break; case 4: echo "? Upper? File "; break ;}} else {if (! Is_dir ('. /upfile/') mkdir ('. /upfile/'); $ path = '. /upfile /'. time (). $ _ FILES ['up _ picture '] ['name']; if (is_uploaded_filed ($ _ FILES ['up _ picture'] ['tmp _ name']) {if (! Move_uploaded_file ($ _ FILES ['up _ picture '] ['tmp _ name'], $ path) {echo "on? Lost ?! ";} Else {echo" file ". time (). $ _ FILES ['up _ picture '] ['name']." on? Success, size?: ". $ _ FILES ['up _ picture '] ['size'] ;}} on else {echo? File ". $ _ FILES ['up _ picture '] ['name']." illegal ";}}}?>

4. file?

?? Introduction? ? In http mode? File, mainly use the header () letter ?. Header () letter ?? For HTTP letters ?, Its role is HTTP? HTML text? ? Sent ?? ,? Sue ??? Appliance? How ?? Why ??? .

Void header (string [, bool replace [, int http_respone_code]); //? Specified by string? Sent ??.?? Replace control if? More ???,? Similar ?? Is it replaced ?? Yes. If it is false ,?? ? Send more? Same? Type ??, Mo ?? True .?? Http_respone_code? ? HTTP ?? Generation ?? Set? Value:

Lower? Step? As follows:

A): pass? "Content-Type" specifies the object's MIME? Type.

B): pass? "Content-Disposition "? File? Line description, value: "attachment; filename =" test.jpg ""? Is it clear? Fujian, same? ? File name ?.

C): Communication? "Content-Length "? ? File size.

D): pass? Readfile () letter ?? Getting files? .

For example: header ('content-Type: image/jpg '); header ('content-Disposition: attachment; filename = "test.jpg"'); header ('content-Length: '.filesize('test.jpg ') must begin readfile('test.jpg ');

5 .??? Process File

Step? 1: configure the php. ini file ?? Allow_url_fopen? Set? On .?? Mo? Yes ?? ? ? Specified by http and ftp? Program file. If allow_url_fopen? Set? Off ,? Not allowed? ?? Program file.

Step? 2: Use the fopen () letter ?? Getting files? . Root ?? Rong? What do you want? Source, save to local.

        

Ps: more file operations and object operations in the php. ini configuration file? Operated? Exhibition method ?? Official php guide.

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.