Server-Side Scripting/Strings and Files

From Wikiversity
Jump to navigation Jump to search

This lesson introduces string and uploaded file processing.

Objectives and Skills[edit | edit source]

Objectives and skills for this lesson include:

  • Understand string processing
  • Understand file processing
  • Upload files to server-side scripts
  • Process text files using server-side scripts

Readings[edit | edit source]

  1. Wikipedia: String (computer science)
  2. Wikipedia: Computer file
  3. Wikipedia: Upload

Multimedia[edit | edit source]

  1. YouTube: Go Simple HTTP File Upload Tutorial
  2. YouTube: How To Upload Files With Node.js
  3. YouTube: PHP File Upload
  4. YouTube: Uploading files with Flask

Examples[edit | edit source]

A data file for these examples may be downloaded from Wikidata: Countries and Temperatures. Select the hidden Wikidata right toolbar and Download / CSV file.

Activities[edit | edit source]

Complete the following activities using HTML, CSS, and a server-side scripting language. Apply best practices for user interface design and your selected scripting language, including modules, comments, indentations, naming conventions, and constants. Use HTML forms, input elements, and text files for input, server-side scripts for processing, and HTML elements for output. Use separate functions for each type of processing. Avoid global variables by passing parameters and returning results. Add comments at the top of the code modules and include references to any resources used. Add the completed code to your website as /lesson5. For each activity, sample test data may be downloaded from the Wikidata link using the Wikidata hidden right toolbar and selecting Download / CSV file.

  1. Review Wikipedia: Saffir–Simpson scale and Wikidata: Tropical Cyclones and Maximum Sustained Winds. Create an application that allows the user to select and upload a comma-separated-values file containing dates, storm names, and maximum sustained winds in kilometers per hour. For each storm, display the maximum sustained winds in miles per hour, kilometers per hour, and the Saffir-Simpson scale category for the storm. Use CSS formatting to color-code the data based on storm category, similar to Wikipedia:Template:Saffir-Simpson scale.
  2. Review Wikipedia: Moment magnitude scale and Wikidata: Earthquakes and Moment Magnitudes Since 2000 C.E.. Create an application that allows the user to select and upload a comma-separated-values file containing dates, earthquake names, and moment magnitudes. For each earthquake, display the earthquake name, moment magnitude, and a magnitude description. See Wikipedia:Richter magnitude scale#Richter magnitudes for magnitude description ranges (Micro, Minor, Light, etc.). Use CSS formatting to color-code the data based on magnitude description.
  3. Review Wikipedia:Wildfire and Wikidata: Wildfires and Area. Create an application that allows the user to select and upload a comma-separated-values file containing dates, wildfires, and area impacted. Display the wildfire information. Use CSS formatting to color-code the data based on the order of magnitude of area impacted (1, 10, 100, 1,000, etc.).
  4. Review Wikipedia:Tsunami and Wikidata: Tsunamis by Date. Create an application that allows the user to select and upload a comma-separated-values file containing dates, tsunamis, continents, and countries. Display the tsunami information. Use CSS formatting to color-code the data based on continent.

Lesson Summary[edit | edit source]

Additional items may be contributed by course participants

  • Strings are a series of characters used by a computer program. Strings are implemented differently in different programming languages. They can be null-terminated, or byte- and bit- terminated, or defined with a prefix length. Most languages allow for different string manipulation like concatenating strings together or splitting them apart into substrings. It is beneficial to become familiar with some string manipulation options available in the language you are working.[1]
  • Files can be uploaded to a server and processed as a typical client-server model. Files can also be transferred between two remote systems by another local system which is known as remote uploading.[2]
  • Express requires the use of specific middleware for uploading files.[3]

Key Terms[edit | edit source]

Additional items may be contributed by course participants

Comma Separated Values (CSV) file
A text file that, as its name says, contains values separated by commas. It simulates a table, where each row is a new line and each column is separated by a comma.[4]
data file
A computer file which stores data to be used by a computer application or system, including input and output data. Data files do not usually contain executable code.[5]
enctype
An HTML form attribute that specifies how the form-data should be encoded when submitting it to the server.[6]
<input type="file">
<input> elements with type="file" let the user choose one or more files from their device storage. Once chosen, the files can be uploaded to a server using form submission, or manipulated using JavaScript code and the File API.[7]
multipart/form-data
multipart/form-data is a value of enctype attribute. The multi-part means form data divides into multiple parts and send to a server.[8]
parser
A software component that takes input data (frequently text) and builds a data structure - often some kind of parse tree, abstract syntax tree or other hierarchical structure, giving a structural representation of the input while checking for correct syntax.[9]
string
A data type that is a sequence of characters, though they look like plain text they are typically an array where the indices represent the individual characters. They are useful for holding data that can be represented in text form.[10]
upload
Transmission of a file from one computer system to another, usually a larger computer system.[11]

See Also[edit | edit source]

References[edit | edit source]

  1. TutorialsPoint: Computer Programming - Strings
  2. Wikipedia: Upload
  3. "express-fileupload". npm. Retrieved 2021-02-19.
  4. https://en.wikipedia.org/wiki/Comma-separated_values
  5. https://en.wikipedia.org/wiki/Data_file#:~:text=A%20data%20file%20is%20a,programs%20work%20with%20data%20files.
  6. https://www.w3schools.com/tags/att_form_enctype.asp
  7. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file Mozilla: <input type="file">
  8. https://medium.com/@danishkhan.jamia/upload-data-using-multipart-16b54866f5bf
  9. https://en.wikipedia.org/wiki/Parsing#Parser
  10. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
  11. WhatIs | Uploading