PHP HOME
PHP Introduction
PHP SETUP
PHP Syntax
PHP Data Types
PHP Outputs
PHP Variable
PHP Constant
PHP Strings
PHP Operators
PHP if else if
PHP Switch
PHP while loop
PHP for loop
PHP Arrays
PHP Functions
PHP Sorting Array
PHP Form Handling
PHP Form Validation
PHP Form Required
PHP Form URL/EMAIL
PHP Form Submit
PHP Contact Form
PHP DATE & TIME
PHP INCLUDE
PHP FILE HANDLING
PHP FILE OPEN/READ
PHP FILE CREATE/WRITE
PHP FILE UPLOAD
PHP SESSION
PHP COOKIES
PHP FILTER
PHP ERROR HANDLING
PHP EXCEPTION
PHP Redirects
PHP with MySQL
PHP WITH MYSQL DB
MYSQL CONNECT
MYSQL CREATE DATABASE
SELECT DATABASE
MYSQL CREATE TABLE
MYSQL INSERT DATA
MYSQL SELECT DATA
MYSQL UPDATE DATA
MYSQL DELETE DATA
MYSQL ORDER
MYSQL LIMIT
MYSQL LAST ID
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.
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.