SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP File Function

PHP File open to read internal file

WE can open a file or a URL to read by using fopen() function of PHP. While opening we can  give mode of file open ( read, write.. etc ). By using fopen we can read any external url also. We can write to a file by using fwrite function. Let us start with reading one internal file ( of the same site ). We have a file name as delete.htm. We will use the command fopen() to open the file in read mode. 

We will be using fread() function to read the content by using a file pointer. Fread() reads up to length bytes from the file pointer referenced  by fd. Reading stops when length bytes have been read or EOF is reached, whichever comes first.

We have also used the function filesize() to know the size of the file and used it in the fread function.
We will be using all these functions to read the content of another file and print the content as out put. Here is the code.

<?Php
$filename = "delete.htm"; // This is at root of the file using this script.
$fd = fopen ($filename, "r"); // opening the file in read mode
$contents = fread ($fd, filesize($filename)); // reading the content of the file
fclose ($fd);               // Closing the file pointer
echo $contents;              // printing the file content of the file
?>

Opening a URL by file_get_contents()

Number of User Comments : 3


Google+
Nicholas17-03-2010
Great lessons.
Thank you very much :-)
Ram28-07-2010
Very simple & useful.., Thanks a lot
ravi08-12-2012
this code open the file in read format but the file is in encrypted format..its unreadable.please tell me the solution of this.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer