PHP Advanced Tutorials (3):P hp file processing

Source: Internet
Author: User
Tags filegroup http post
The fopen () function is used to open the file in PHP.

Open File

The fopen () function is used to open the file in PHP.

The first parameter of this function contains the name of the file to be opened, and the second parameter specifies which mode to use to open the file:

<body>

<?php
$file =fopen ("Welcome.txt", "R");
?>

</body>

The file may be opened in the following mode:

Example

If fopen () cannot open the specified file, the following example generates a message: 

Example

The following example reads the file row by line until the end of the file: <?php$file = fopen ("Welcome.txt", "R") or exit ("Unable to open file!"); /output a line of the file until the end is Reachedwhile (!feof ($file))  {  echo fgets ($file). "<br/>";  } Fclose ($file);? The > character read file fgetc () function is used to read files verbatim from a file. Note: After the function is called, the file pointer moves to the next character.

Example

The following example reads a file verbatim until the end of the file: <?php$file=fopen ("Welcome.txt", "R") or exit ("Unable to open file!"); while (!feof ($file))   {   echo fgetc ($file);   } Fclose ($file);? >php Filesystem Reference Manual for a complete PHP file System Reference manual PHP Filesystem Introduction Filesystem functions allow you to access and manipulate file systems. Installing the FileSystem function is part of the PHP core. These functions can be used without installation. The behavior of the Runtime Profile system function is affected by the settings in php.ini. File System configuration options:

Unix/windows compatibility

When a path is specified on a Unix platform, a forward slash (/) is used as the directory delimiter. On the Windows platform, both the forward slash (/) and the backslash (\) can be used.

PHP Filesystem functions

PHP: Indicates the earliest version of PHP that supports this function.

Function Description PHP

BaseName () returns the file name portion of the path. 3

CHGRP () changes the filegroup. 3

chmod () changes the file mode. 3

Chown () changes the file owner. 3

Clearstatcache () Clears the file state cache. 3

Copy () copies the file. 3

Delete () See unlink () or unset ().

DirName () returns the directory name portion of the path. 3

Disk_free_space () returns the free space for the directory. 4

Disk_total_space () returns the total disk capacity of a directory. 4

Alias of Diskfreespace () Disk_free_space (). 3

Fclose () closes the open file. 3

Feof () tests whether the file pointer is to the end of the file. 3

Fflush () outputs the buffered content to the open file. 4

FGETC () returns characters from an open file. 3

Fgetcsv () parses a row from an open file and verifies the CSV field. 3

Fgets () returns a row from the open file. 3

FGETSS () reads a row from the open file and filters out HTML and PHP tags. 3

File () reads the files into an array. 3

File_exists () checks whether a file or directory exists. 3

File_get_contents () reads the file into the string. 4

File_put_contents writes a string to the file. 5

Fileatime () returns the last access time of the file. 3

Filectime () returns the last time the file was changed. 3

Filegroup () returns the group ID of the file. 3

Fileinode () returns the inode number of the file. 3

Filemtime () returns the last modified time of the file. 3

The user ID (owner) of the Fileowner () file. 3

Fileperms () returns the file's permissions. 3

FileSize () returns the file size. 3

FileType () returns the file type. 3

Flock () locks or releases files. 3

Fnmatch () matches the file name or string according to the specified pattern. 4

fopen () opens a file or URL. 3

Fpassthru () reads the data from the open file until EOF, and writes the result to the output buffer. 3

Fputcsv () formats the row as CSV and writes to an open file. 5

Alias of Fputs () fwrite (). 3

Fread () reads the open file. 3

FSCANF () parses the input according to the specified format. 4

Fseek () locates in the open file. 3

Fstat () returns information about an open file. 4

Ftell () returns the read/write position of the file pointer 3

Ftruncate () truncates the file to the specified length. 4

Fwrite () writes the file. 3

Glob () returns an array that contains the file name/directory that matches the specified pattern. 4

Is_dir () Determines whether the specified file name is a directory. 3

Is_executable () Determines whether the file can be executed. 3

Is_file () Determines whether the specified file is a regular file. 3

Is_link () Determines whether the specified file is a connection. 3

Is_readable () Determines whether the file is readable. 3

Is_uploaded_file () determines if the file was uploaded via HTTP POST. 3

Is_writable () Determines whether the file is writable. 4

Alias of Is_writeable () is_writable (). 3

Link () Creates a hard connection. 3

LinkInfo () returns information about a hard connection. 3

Lstat () returns information about a file or symbolic connection. 3

mkdir () to create a directory. 3

Move_uploaded_file () Moves the uploaded file to a new location. 4

parse_ini_file () resolves a configuration file. 4

PathInfo () returns information about the file path. 4

Pclose () closes the process with Popen () open. 3

Popen () opens a process. 3

ReadFile () reads a file and outputs it to the output buffer. 3

Readlink () returns the target of the symbolic connection. 3

Realpath () returns the absolute path name. 4

Rename () name file or directory. 3

Rewind () returns the position of the file pointer. 3

RmDir () Delete the empty directory. 3

Set_file_buffer () sets the buffer size of the open file. 3

Stat () returns information about the file. 3

Symlink () Creates a symbolic connection. 3

Tempnam () creates a unique temporary file. 3

Tmpfile () Create a temporary file. 3

Touch () Sets the file's access and modification times. 3

Umask () Change file permissions for files. 3

Unlink () delete the file. 3

PHP Filesystem Constants

PHP: Indicates the earliest version of PHP that supports this constant.

The above is the PHP Advanced Tutorial (3):P hp file processing content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.