PHP Basic Tutorial--4 File and Directory Learning summary

Source: Internet
Author: User

First, write the file:
$fp = fopen (FileName, mode);
Mode for open file mode such as ' A + ' means to read and write files, file does not exist to create, new data main added to the end of the file

fwrite ($fp, write content );

Fclose ($FP);

Second, lock the file: when there are multiple users at the same time on the file operation to ensure that there is no conflict

Fclock ($FP, lock type); Lock types include write-exclusive, read-share ...

Third, read the file:

$data = file (' filename path ');

Places the data that is read into the array of data, with each element being a line of the file.

Coding test: ws.php:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > 
Test drawing:

Starting:


Results:




V. Handling file uploads:

The 1.form tag must contain: Enctype= "Multipart/form-data", the form must be using the Post method

2. A hidden input box must be added and the maximum upload file size (in bytes) of the browser is recommended.

3. Create form fields <input type= "file" name= "Thefile"/>

Code test: ws.php:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > 
VI. Catalogue

1. Navigation directory:

Find all contents in directory: Scandir ();

eg: $stuff = scandir (' directory name ');//function returns an array containing the files and directories in the directory, copied to $stuff

2. Create a directory:

mkdir (' path name ');


PHP Basic Tutorial--4 File and Directory Learning summary

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.