GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/nginx/html/JimMartinson/CST1146/Resources/Examples/Week/09/ |
Upload File : |
<!DOCTYPE html> <html> <body> <h2>Open and read a file</h2> <?php $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!"); #echo fread($myfile,filesize("webdictionary.txt")); echo "First 10 bytes: "; echo fread($myfile,10); // Only the first 10 bytes. echo "<br>Next 10 bytes: "; echo fread($myfile,10); echo "<br>The rest: "; echo fread($myfile,filesize("webdictionary.txt")); echo "<br>Try to read more when the entiref ile has been read: "; echo fread($myfile,10); fclose($myfile); ?> <h2>Write to a file</h2> <?php /**/ $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $txt = "John Doe\n"; fwrite($myfile, $txt); $txt = "Jane Doe\n"; fwrite($myfile, $txt); fwrite($myfile, 'Jim martinson\n'); fwrite($myfile, "Jim martinson\n"); fclose($myfile); /**/ ?> <h2>Rewrite the file</h2> <?php /**/ $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $txt = "Mickey Mouse\n"; fwrite($myfile, $txt); $txt = "Minnie Mouse\n"; fwrite($myfile, $txt); fclose($myfile); /**/ ?> <h2>Add more to the file</h2> <?php $myfile = fopen("newfile.txt", "a") or die("Unable to open file!"); $txt = "Goofy\n"; fwrite($myfile, $txt); fclose($myfile); ?> <h2>Read a file and play with the contents</h2> <?php $myfile = fopen("newfile.txt", "r") or die("Unable to open file!"); $contents = fread($myfile,filesize("newfile.txt")); fclose($myfile); ?> <pre><?=var_dump($contents)?></pre> <h2>File line by line</h2> <?php $lines = explode("\n",$contents); for ($i=0; $i<count($lines); $i++) { $thisLine = $lines[$i]; echo $thisLine."<br>"; } foreach ($lines as $thisLine) { $newLine = str_replace("Mouse","Moose",$thisLine); echo $newLine."<br>"; } ?> </body> </html>