<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
<?php
// Open the text file
$f = fopen("textfile.txt", "w");
// Write text
fwrite($f, $_POST["textblock"]);
// Close the text file
fclose($f);
// Open file for reading, and read the line
$f = fopen("textfile.txt", "r");
// Read text
echo fgets($f);
fclose($f);
?>
</body>
</html>
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 16
Warning: fopen(textfile.txt): Failed to open stream: Operation not permitted in /in/094ca on line 16
Warning: Undefined array key "textblock" in /in/094ca on line 19
Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, false given in /in/094ca:19
Stack trace:
#0 /in/094ca(19): fwrite(false, NULL)
#1 {main}
thrown in /in/094ca on line 19
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 16
Warning: fopen(textfile.txt): Failed to open stream: Operation not permitted in /in/094ca on line 16
Warning: Undefined array key "textblock" in /in/094ca on line 19
Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, false given in /in/094ca:19
Stack trace:
#0 /in/094ca(19): fwrite(false, NULL)
#1 {main}
thrown in /in/094ca on line 19
Process exited with code 255.
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 16
Warning: fopen(textfile.txt): Failed to open stream: Operation not permitted in /in/094ca on line 16
Warning: Undefined array key "textblock" in /in/094ca on line 19
Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /in/094ca:19
Stack trace:
#0 /in/094ca(19): fwrite(false, NULL)
#1 {main}
thrown in /in/094ca on line 19
Process exited with code 255.
Output for 8.0.13
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(textfile.txt): Failed to open stream: Read-only file system in /in/094ca on line 16
Warning: Undefined array key "textblock" in /in/094ca on line 19
Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /in/094ca:19
Stack trace:
#0 /in/094ca(19): fwrite(false, NULL)
#1 {main}
thrown in /in/094ca on line 19
Process exited with code 255.
Output for 7.4.33
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(textfile.txt): failed to open stream: Read-only file system in /in/094ca on line 16
Notice: Undefined index: textblock in /in/094ca on line 19
Warning: fwrite() expects parameter 1 to be resource, bool given in /in/094ca on line 19
Warning: fclose() expects parameter 1 to be resource, bool given in /in/094ca on line 22
Warning: fopen(textfile.txt): failed to open stream: No such file or directory in /in/094ca on line 25
Warning: fgets() expects parameter 1 to be resource, bool given in /in/094ca on line 28
Warning: fclose() expects parameter 1 to be resource, bool given in /in/094ca on line 29
</body>
</html>
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 16
Warning: fopen(textfile.txt): failed to open stream: Operation not permitted in /in/094ca on line 16
Notice: Undefined index: textblock in /in/094ca on line 19
Warning: fwrite() expects parameter 1 to be resource, bool given in /in/094ca on line 19
Warning: fclose() expects parameter 1 to be resource, bool given in /in/094ca on line 22
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 25
Warning: fopen(textfile.txt): failed to open stream: Operation not permitted in /in/094ca on line 25
Warning: fgets() expects parameter 1 to be resource, bool given in /in/094ca on line 28
Warning: fclose() expects parameter 1 to be resource, bool given in /in/094ca on line 29
</body>
</html>
Output for 7.3.32 - 7.3.33
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(textfile.txt): failed to open stream: Read-only file system in /in/094ca on line 16
Warning: fwrite() expects parameter 1 to be resource, bool given in /in/094ca on line 19
Warning: fclose() expects parameter 1 to be resource, bool given in /in/094ca on line 22
Warning: fopen(textfile.txt): failed to open stream: No such file or directory in /in/094ca on line 25
Warning: fgets() expects parameter 1 to be resource, bool given in /in/094ca on line 28
Warning: fclose() expects parameter 1 to be resource, bool given in /in/094ca on line 29
</body>
</html>
Output for 7.1.25, 7.2.0 - 7.2.33
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 16
Warning: fopen(textfile.txt): failed to open stream: Operation not permitted in /in/094ca on line 16
Notice: Undefined index: textblock in /in/094ca on line 19
Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/094ca on line 19
Warning: fclose() expects parameter 1 to be resource, boolean given in /in/094ca on line 22
Warning: fopen(): open_basedir restriction in effect. File(textfile.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/094ca on line 25
Warning: fopen(textfile.txt): failed to open stream: Operation not permitted in /in/094ca on line 25
Warning: fgets() expects parameter 1 to be resource, boolean given in /in/094ca on line 28
Warning: fclose() expects parameter 1 to be resource, boolean given in /in/094ca on line 29
</body>
</html>
<html>
<head>
<title>Write to a text file</title>
</head>
<body>
<h1>Adding a text block to a text file:</h1>
<form action="myfile.php" method='post'>
<textarea name='textblock'></textarea>
<input type='submit' value='Add text'>
</form>
Warning: fopen(textfile.txt): failed to open stream: Permission denied in /in/094ca on line 16
Notice: Undefined index: textblock in /in/094ca on line 19
Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/094ca on line 19
Warning: fclose() expects parameter 1 to be resource, boolean given in /in/094ca on line 22
Warning: fopen(textfile.txt): failed to open stream: No such file or directory in /in/094ca on line 25
Warning: fgets() expects parameter 1 to be resource, boolean given in /in/094ca on line 28
Warning: fclose() expects parameter 1 to be resource, boolean given in /in/094ca on line 29
</body>
</html>