Php: working with files
"Language Php" is a programming language. It basically writes all the sites that exist on the Internet. It is very difficult to describe the entire language, but this article is devoted to creating files and working with them.
Language Php: work with files
During the process of creating files on the Php is usedspecial, original image. In the standard set of Php functions there are no special features, thanks to which you can work with different files. You can only find one special function fopen (), which is used to establish a connection with the file. But there is such a feature: if the file that is requested is not available, the system automatically creates a new file that has exactly the same name.
Resource fopen (NAME, TYPE). The NAME will help you create or specify file names that are created or already in existence. TYPE - the type of file you are applying to and with which you want to work afterwards.
The access type can take different values. In Php, working with files means several types of action on a file.
R - Set the pointer at the beginning of the file and open the file for reading.
R + - Set the pointer at the beginning of the file and open it for reading or writing in simultaneous mode.
W - If the file is available, then itsthe content is deleted and it opens for writing. If it does not exist, a new one with the same name is created. After you perform actions on these files, they close and save the data. fclose () and will serve as the procedure for closing the file.
In Php, work with files is done in thosecases, when it is necessary to perform certain actions in relation to these files: creation, editing, recording or deletion. When you create a Php page, you work with files according to the syntax of this language, which is described above.
Deleting a Php file
To work on a local computer with filesPhp, you need to install a local server that, like the real one, will emulate the work and link the Php pages to the database. Php files are created on such a local server, and they are also deleted only through it. To do this, you need to go to the local server, find the desired file and delete it. In order to be able to delete ordinary files by accessing them through the Php page, there are special language functions that will allow you to implement this simple process.
Deleting duplicate files
When working with Php files can ariseproblems if you have several identical files. You can delete them through a virtual machine, directly into the trash, leaving only the one that is needed. Or, if both are needed, then you can rename them. In order to delete ordinary files with the same names, you can use specially written for these purposes squeaks. They are inserted into the Php page and at the right moment work, doing all the work for the programmer.
Like in any other programming language, in Php there are several options for working with files.
- Open the file for reading.
- Open the file for reading or writing.
- Create a new file.
- Delete the file.
- Renaming a file.
The first three functions are described above. The fourth is implemented using the special function unlink Php. This function allows you to find the desired file among all available in the directory to which it was sent, and delete it. The fifth action can be performed manually, by finding a file and renaming it. Or, when working, the overwrite function itself can clear the file and, when saving, assign the desired name to it.
Working with files in Php is not like other languagesprogramming, but the syntax of the language is the same as in the "c ++" language, which makes it easy to understand those who have encountered the "si" language. To learn the Php language, you have to spend considerably less time if you know the basics of programming.