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 : /nginx/html/JimMartinson/CST1146/Labs/Lab07/ |
Upload File : |
<? // JimMartinson/CST1146/Labs/Lab07/Lab07.phpinc #if ( $_SESSION['userId'] == 1 ) $showEvaluationVariables = true; require('Gradebook/EvaluationSubmission_BEGIN.phpinc'); // Replaced. #if ( $_SESSION['userId'] != 1 ) { require('Gradebook/EvaluationSubmission_END.phpinc'); exit; } include('common/Browser/Browser.phpinc'); $disabled = ''; $disabled = ' disabled'; // Comment this line to enable lab. // NOTE: Disable Include conf/extra/httpd-autoindex.conf line in the httpd.conf file before labs. // OR: Fix labs so Lab 4 mod_autoindex works as it should. ?> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Description</legend> The purpose of this lab is to demonstrate the use of php file includes and manipulation. <br><span class="note normal">You will be writing four php files for this assignment.</span> <?=$gradeNote?> <? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <fieldset><legend><?=$evaluationType?> <?=$evaluationNumber?> Instruction</legend> <ol class="count"> <!-- 1 --> <li>Create a directory called <b class="copyText"><?=$evaluationName?></b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?></b> directory. We will use it for all work performed in this lab.</li> <!-- 2 --> <li>Code a PHP file for include/require: <ol> <li>Create a PHP file named <b class="copyText">application.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Write a function called <b class="copyText">beginPage</b> which takes one parameter named <b class="copyText">$title</b>. <br><span class="note">The purpose of this function is to output the beginning of an html document.</span> <ol> <li>Code the beginPage function so it outputs the beginning code of an html document with the following: <ol> <li>The HTML 5 DOCTYPE: <span class="html copyText"><!DOCTYPE html></span>.</li> <li>An start html tag with the <span class="highATT">lang</span> attribute set to <span class="highVAL">en</span>: <span class="html copyText"><html lang="en"></span>.</li> <li>A <span class="html">head</span> section containing: <ol style="list-style-type: lower-roman"> <li>A <span class="html">title</span> element with the title contents being the value of the <b>$title</b> variable.</li> <li>A meta tag that defines the character set <span class="html copyText"><meta charset="utf-8"></span>.</li> </ol> </li> <li>A start <span class="html">body</span> tag: <span class="html copyText"><body></span>.</li> <li>An <span class="html">h1</span> heading with the contents being the value of the <b>$title</b> variable.</li> </ol> </li> </ol> </li> <li>Write a function called <b class="copyText">endPage</b> which takes no parameters. <br><span class="note">The purpose of this function is to output the end code of an html document.</span> <ol> <li>Code the endPage function so it outputs the end of an html document with the following: <ol> <li>The html code: <br><span class="html copyText nowrap"><footer style="color:silver; font-size:smaller;">Written by <?=$userFullName?>.</footer></span></li> <li>A stop <span class="html">body</span> tag: <span class="html copyText"></body></span>.</li> <li>A stop <span class="html">html</span> tag: <span class="html copyText"></html></span>.</li> </ol> </li> </ol> </li> <li>Save the <b>application.php</b> file.</li> </ol> </li> <!-- 3 --> <li>Code a PHP file to create and write text to a file: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_Create.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b>application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Create a file</b>.</li> <li>Open a file named <b class="copyText"><?=$saveFilename?>_Text.txt</b> so it will create the file if it does not exist or truncate it if the file exists.</li> <li>Use a loop to write the following lines into the file using PHP: <ul> <li><b class="copyText">This is line 1.</b></li> <li><b class="copyText">This is line 2.</b></li> <li><b class="copyText">This is line 3.</b></li> <li><b class="copyText">This is line 4.</b></li> </ul> <span class="note">Each of the above lines must be on a serarate line in the file.</span> </li> <li>Close the <b class="copyText"><?=$saveFilename?>_Text.txt</b> file.</li> <li>Display the text: <b class="copyText">Created a file named <?=$saveFilename?>_Text.txt.</b></li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_Create.php</b> file.</li> <li>Verify that your <b><?=$saveFilename?>_Create.php</b> page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open the <b><?=$saveFilename?>_Create.php</b> page in a browser.</li> <li>You should see a page like:<br> <? BrowserBegin('Create a file','http://localhost/CST1146/'.$evaluationName.'/'.$saveFilename.'_Create.php',820); ?> <h1 class="left">Create a file</h1> Created a file named <?=$saveFilename?>_Text.txt. <br><span style="color:silver; font-size:smaller">Written by <?=$userFullName?>.</span> <? BrowserEnd(); ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_Create.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> <note class="normal"> A file called <b><?=$saveFilename?>_Text.txt</b> should now be in your <b><?=$evaluationName?></b> folder. <br>It should only contain the four lines above. <br>If you reload the page, the <b><?=$saveFilename?>_Text.txt</b> file will still only contain the four lines from step 3.5. </note> </li> </ol> </li> <!-- 4 --> <li>Code a PHP file to write more text to a file: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_More.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b>application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Add more text</b>.</li> <li>Open the <b><?=$saveFilename?>_Text.txt</b> file so you can append text to the file.</li> <li>Write the following line at the end of the file: <b class="copyText">This is an additional line added by <?=$userFullName?>.</b>. <span class="note">The line must be on a serarate line in the file.</span> </li> <li>Close the <b class="copyText"><?=$saveFilename?>_Text.txt</b> file.</li> <li>Display the text: <b class="copyText">Another line was appended to <?=$saveFilename?>_Text.txt.</b></li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_More.php</b> file.</li> <li>Verify that your <b><?=$saveFilename?>_More.php</b> page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open the <b><?=$saveFilename?>_More.php</b> page in a browser.</li> <li>You should see a page like:<br> <? BrowserBegin('Add more text','http://localhost/CST1146/'.$evaluationName.'/'.$saveFilename.'_More.php',820); ?> <h1 class="left">Add more text</h1> Another line was appended to <?=$saveFilename?>_Text.txt. <br><span style="color:silver; font-size:smaller">Written by <?=$userFullName?>.</span> <? BrowserEnd(); ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_More.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> <note class="normal"> The <b><?=$saveFilename?>_Text.txt</b> should now contain the original four lines plus the text from step 4.5 on a new line. <br>Every time you reload the page, the <b><?=$saveFilename?>_More.php</b> file will have the new line appended at the bottom. </note> </li> </ol> </li> <!-- 5 --> <li>Code a PHP file to read and display the text in a file: <ol> <li>Create a PHP file named <b class="copyText"><?=$saveFilename?>_Read.php</b> in the <b><?=$evaluationName?></b> directory and open it in an editor.</li> <li>Include the <b>application.php</b> file.</li> <li>Call the <b class="php">beginPage</b> function with a parameter of <b class="copyText">Read a file</b>.</li> <li>Add an <span class="html">h2</span> heading with the content: <span class="html copyText">This is the content of the <?=$saveFilename?>_Text.txt file</span>.</li> <li>Open the <b><?=$saveFilename?>_Text.txt</b> file in read only mode.</li> <li>Read the contents of the <b><?=$saveFilename?>_Text.txt</b> file and display the contents.<br>Each line in the file should display on a new line of the page.<br> <span class="note"> Set a variable equal to the return value of the <a href="https://www.php.net/manual/en/function.fread.php">fread()</a> function. <br>Then use one of these methods for displaying the lines from the file one at a time: <ul> <li>Use <a href="https://www.php.net/manual/en/function.explode.php">explode()</a> on "\n" to put the lines into an array and <a href="https://www.php.net/manual/en/control-structures.foreach.php">foreach</a> to loop thru the array.</li> <li>Use a <a href="https://www.php.net/manual/en/control-structures.while.php">while</a> loop and the <a href="https://www.php.net/manual/en/function.feof.php">feof()</a> function to see if you have read the entire file and the <a href="https://www.php.net/manual/en/function.fgets.php">fgets()</a> function to read the lines one at a time.</li> </ul> </span> </li> <li>Close the <b class="copyText"><?=$saveFilename?>_Text.txt</b> file.</li> <li>Call the <b class="php">endPage</b> function</li> <li>Save the <b><?=$saveFilename?>_Read.php</b> file.</li> <li>Verify that your <b><?=$saveFilename?>_Read.php</b> page works. <ol type="i"> <li>Start Apache if it is not running.</li> <li>Open the <b><?=$saveFilename?>_Read.php</b> page in a browser.</li> <li>You should see a page like:<br> <? BrowserBegin('Read a file','http://localhost/CST1146/'.$evaluationName.'/'.$saveFilename.'_Read.php',820); ?> <h1 class="left">Read a file</h1> <h2>This is the content of the <?=$saveFilename?>_Text.txt file</h2><br> <? $file = fopen("JimMartinson_Lab07_Text.txt", "r") or die("Unable to open file!"); $contents = fread($file, filesize("JimMartinson_Lab07_Text.txt")); fclose($file); $lines = explode("\n", $contents); foreach($lines as $line){ echo $line, "<br>\n"; } ?> <div style="color:silver; font-size:smaller">Written by <?=$userFullName?>.</div> <? BrowserEnd(); ?> If this is not what you see then you have errors in your code. </li> <li><b class="info">Take a screenshot of the page</b> and save the image as <b class="copyText"><?=$saveFilename?>_Read.png</b> in your <b><?=$dataFolder?><?=$dirSep?><?=$courseNumber?><?=$dirSep?><?=$evaluationName?></b> directory. <br>Make sure that the address bar is visible in your browser before saving the image. </li> </ol> </li> </ol> <div id="show_page" class="inline code"><a href="#" onClick="divHide('show_page'); divShow('hide_page'); return false;">See example html code produced by <?=$saveFilename?>_Read.php:</a></div> <div id="hide_page" class="hidden code"><a href="#" onClick="divHide('hide_page'); divShowInline('show_page'); return false;">Hide the example.</a> <pre><!DOCTYPE html> <html lang="en"> <head> <title>Read a file</title> <meta charset="utf-8"> </head> <body> <h1>Read a file</h1> <h2>This is the content of the JimMartinson_Lab07_Text.txt file</h2> This is line 1.<br> This is line 2.<br> This is line 3.<br> This is line 4.<br> This is an additional line added by Jim Martinson.<br> <footer style="color:silver; font-size:smaller;">Written by Jim Martinson.</footer> </body> </html></pre> </div> </li> <!-- 6 --> <li>Turn in your assignment: <ol> <li>Ensure the following files are in your <b><?=$evaluationName?></b> folder. <? $fileList = array( 'application.php', $saveFilename.'_Create.php', $saveFilename.'_Create.png', $saveFilename.'_More.php', $saveFilename.'_More.png', $saveFilename.'_Read.php', $saveFilename.'_Read.png', $saveFilename.'_Text.txt', ); natcasesort($fileList); foreach ($fileList as $fileName) { ?> <br><?=$fileName?> <? } ?> </li> <li>Zip up your <b><?=$evaluationName?></b> folder into a file named <b class="copyText"><?=$uploadFilename?></b>.</li> <li>Browse and select your <b><?=$uploadFilename?></b> file: <input type="file" name="fileUpload" id="inpFileUpload"<?=$disabled?>><div id="divFileploadError"></div></li> <li>Then <input type="submit" name="f_subtask" id="inpSubmit" value="Submit"<?=$disabled?>> for grading.</li> </ol> </li> <!-- 7 --> <!-- 8 --> <!-- 9 --> <!-- 10 --> </ol><? if ( $disabled ) { ?><span class="error bold">Notice: Do not perform this assignment unless this notice has been removed.</span><? } ?> </fieldset> <? require('../LabNotes.phpinc'); require('Gradebook/EvaluationSubmission_END.phpinc'); // Replaced. ?>