saftutorials.com
PHP FILE OPEN/READ

If you want to open a file that store in you server but should open it using PHP, then you can call fopen() function where. 


Syntax of fopen() function

fopen(filename, mode) - the first parameter is the file name and second is the purpose of file open means I which mode you want to open


An example of PHP fopen() function


This is the text file named test.txt

PHP stands for Hypertext Processor
PHP is server side language while JavaScript is client side language.
PHP files contains  HTML, CSS, JavaScript, MySQL Query and PHP scripts.
PHP can connect to the database and modify the data tables and database.
PHP can create, delete, open, close, add the file and many other things can do on the server.


This is the main PHP file where call test.txt by fopen() function.

<html>
<head>
<title>Reading a file</title>
</head>
<body>
<?php
$file_name = "test.txt";
$file = fopen( $file_name, "r" );
if( $file == false ) {
echo ( "Error" );
exit();
}
$file_size = filesize( $file_name );
$file_text = fread( $file, $file_size );
fclose( $file );
echo ( "<h2>File size : ".$file_size." bytes</h2>" );
echo ( "<p>$file_text</p>" );
?>
</body>
</html>

The above code produces the following results

File size: 357

PHP stands for Hypertext Processor

PHP is server side language while JavaScript is client side language.

PHP files contains  HTML, CSS, JavaScript, MySQL Query and PHP scripts.

PHP can connect to the database and modify the data tables and database.

PHP can create, delete, open, close, add the file and many other things can do on the server.



Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic