//$filename = "my_file.txt"; // Inside same directory
$filename = "D://my_dir//y23_02.txt"; // Path to file
$fd = fopen ($filename, "r"); // opening the file in read mode
$contents = fread ($fd, filesize($filename)); // reading the content
fclose ($fd);
print($contents);
file
:mode
:r
:r+
:w
:w+
:a
:a+
:x
:x+
:c
:c+
:e
:use_include_path
:context
:$filename = "http://localhost/plus2net/php_tutorial/site_map-file.php"; // local url
$fd = fopen ($filename, "r"); // opening the file in read mode
$contents = fread ($fd, 10000); // reading the content of the
fclose ($fd);
print($contents);
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.
<?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()
Nicholas | 17-03-2010 |
Great lessons. Thank you very much :-) |
Ram | 28-07-2010 |
Very simple & useful.., Thanks a lot |
ravi | 08-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. |
06-02-2023 | |
this is amazing |