Manual of PHP

 
 
 

Web map

 
rim   rim
Carriedarrow Operations with Files

 

Operations with Files To print E-mail

In the development and administration of places webs it turns out to be quite habitual to have to gain access to files of the servant to manipulate them. For this reason in this chapter we are going to describe the functions created in PHP to realize the above mentioned operations.

Change, creation and erasure of directories

chdir (ruta_al_directorio); it allows Us to change the active directory to the route established like parameter.
mkdir (ruta_al_directorio, permissions); This function believe a new directory in the route that we have indicated, the second parameter must be a number octal and it is for that the permissions are determined.
rmdir (ruta_directorio); It erases the directory spent for parameter.

Prosecution of the elements of a directory

Let's suppose that we want to realize an operation determined as a search, visualization, etc on all the files of a directory. PHP provides a solution to us to this problem: the manejador of directories (it represents a logical connection with a certain directory that allows to read the list with the names of the elements contained in the current directory).

The function used to open a directory is opendir (route); whose function as it has already been commented is to open the directory of the stated route. Once it has been executed opendir () we can realize three operations:


The function readdir (manejador); he returns us a chain with the name of the following element of the directory, be already a subdirectory or a file.
The function rewinddir (manejador); it processes a directory and the internal leader places in the first directory.
The function closedir (manejador); it finishes the treatment of earnings of directory.

The class dir

PHP provides a predefined pseudoclass to us for the files handling. This class does not contribute any functionality that we have not seen up to this point but it compiles all the functions from only one. To be able to work with the first directory it is necessary to create a class instance dir by means of his builder. $directorio=dir (ruta_directorio);

This one objected account with 3 methods and 2 properties (the properties only of consultation by what they cannot be modified. The used methods are read (), rewind () and close ()

Copied, erased and renamed of files

copy (fichero_origen, fichero_destino); It realizes a copy of a file.
unlink (nombre_fichero); It eliminates the file.
reyam (nombre_antiguo, nombre_nuevo); It renames the file spent for parameter.

Attributes of files and directories

The files and directories possess a series of proper characteristics named attributes. PHP puts at our disposal a set of functions that will allow us to obtain information about the files or folders.

The function file_exists (element); He verifies that the element spent for parameter exists.

filesize (nombre_fichero); he informs us about the size of the file in bytes.


The function fileatime (file); he informs us about the last access to the file.


The function filemtime (file); he informs us about the last modification of the file.
The function filectime (file); he informs us about the last change to the file.
The function filetype (file); he returns us the type of element that we are treating. The possible results that he can return are:

Result Meaning
block Blocks device
char Characters
dir Directory
fifo FIFO
file File
link Linkage
unknown Stranger

Chmod (elemento_directorio, permissions); it receives like parameter the element and the permissions that we want to grant him to the above mentioned elements

Previous chapter:
Entry and Exit

Following chapter:
The language SQL and PHP



 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

GlobeSpot.Net Web Directory , SEO , Kiteboarding , rf wireless, , ferienhaus polen , speed test , Cheap flights to Poland