Source Code:
(back to article)
<?php // Open the file for reading $file = fopen("file.txt", "w"); // Check if the file was successfully opened if ($file) { // Write fake content to the file fwrite($file, "This is some content."); // Close the file fclose($file); // Open the file for reading again $file = fopen("file.txt", "r"); // Get the size of the file in bytes $file_size = filesize("file.txt"); // Read the contents of the file $contents = fread($file, $file_size); // Output the contents of the file echo $contents; // Close the file fclose($file); } else { // If the file could not be opened, output an error message echo "Error: Could not open the file for writing."; } ?>
Result:
Report an issue