Site icon sharedsapience.info

PHP Filesystem Function Mini-Quiz: From filetype() to fread().

The filetype PHP filesystem function, sized for desktop viewing.

An image of the filetype() PHP filesystem function, sized for desktop viewing.

HOW THE QUIZ WORKS:

Clicking the ‘randomize’ button situated above the reference table generates a new table whereby the function descriptions, function syntaxes, and function return values are randomized. The quiz involves matching the function descriptions, function syntaxes, and function return values to the correct function name. Information relating to the randomization of table cells will be displayed for three seconds, before disappearing.

On a desktop computer, table elements are selected by left-clicking the desired table cell and holding the left click in the mouse down position for one second before releasing the left click. The text inside the table cell will turn red to indicate that the one-second mouse left-click has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second left mouse-click process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second left mouse-click process on the original table cell.

To select a table element on a touchscreen device (mobile, tablet), simply touch the desired table cell and maintain the touch for one second before removing your finger from the screen. The text inside the table cell will turn red to indicate that the one-second touch has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second touch process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second touch process on the original table cell.

Normal touchscreen scrolling behaviour is exhibited by the cells with a light green background; cells without a light green background will not respond to normal touchscreen scrolling. The table is positioned in such a way that the user can also initiate touchscreen scrolling by swiping to the right or left of the table.

When a row consists of the correct function name, function description, function syntax, and function return value, the background colour of the row will change from ‘transparent’ to ‘khaki’; this provides visual feedback that the row is complete.

Once the entire table is complete, a paragraph of feedback will congratulate the user and provide the following information: date and time of quiz commencement; date and time of quiz completion; and the length of time it took the user to complete the quiz.

VIEWPORT OPTIONS:

An example of the layout designed for mobile phones
An example of the layout designed for tablets
An example of the layout designed for desktop computers

PURPOSE:

This webpage serves two purposes:

  1. It provides a reference table for the PHP filesystem functions, with information extracted and condensed from w3schools.com, phptutorial.info and php.net.
  2. It enables users to complete a quiz related to the PHP filesystem functions.

USAGE:

For each filesystem function there are four table cells of information: the function name; the function description; the function syntax; and the function return value. There are three layouts available – ‘mobile‘, ‘tablet‘, and ‘desktop‘.

Click the relevant button below to display the PHP filesystem functions reference table, sized appropriately for the desired viewport. A ‘RANDOMIZE‘ button appears above the reference table once the viewport is selected; clicking this button facilitates the commencement of a quiz.



Click the ‘RANDOMIZE‘ button to randomize the functional descriptions, the functional syntaxes, and the functional return information.


FUNCTION NAME FUNCTION DESCRIPTION FUNCTION SYNTAX FUNCTION RETURN VALUE
filetype()

[filetype – Gets file type]

This function returns the type of the given filename. filetype(filename); filetype(): returns the type of the file – one of fifo, char, dir, block, link, file, socket, and unknown. Returns FALSE and an E_WARNING on failure; if the stat call fails or the file type is unknown, an E_NOTICE message is produced.
flock()

[flock – Portable advisory file locking]

PHP supports a portable way of locking complete files in an advisory way [i.e., all accessing programs have to use the same way of locking it or it will not work]. flock() facilitates the performance of a simple reader/writer model which can be used on virtually every platform. File unlocking has to be done manually, as of PHP version 5.3.2; prior to this, unlocking was done automatically when the resource_handle was closed. flock(resource_handle, operation, would_block [optional parameter]);

[operation can be one of the following values: LOCK_SH; LOCK_EX; LOCK_UN; or LOCK_NB (used as a bitmask to one of the three aforementioned values if you don’t want flock() to block while locking). wouldblock is set to 1 if the lock would block.]

flock(): returns TRUE on success; FALSE on failure. Can only be used on file pointers returned by fopen() for local files, or file pointers pointing to userspace streams that implement the streamWrapper::stream_lock() method.
fnmatch()

[fnmatch – Match filename against a pattern]

This function tests whether the passed string would match the given shell wildcard pattern. This function can be used for regular strings but it is especially useful for testing filenames. fnmatch(pattern, string, flags [optional parameter]);

[The optional flags parameter can be any of the following values, joined by the binary OR operator (|): FNM_NOESCAPE; FNM_PATHNAME; FNM_PERIOD; and FNM_CASEFOLD.]

fnmatch(): returns TRUE if there is a match; FALSE otherwise. At present, this function is unavailable on non-POSIX-compliant systems except for Windows.
fopen()

[fopen – Opens file or URL]

fopen() binds the named resource – specified by filename – to a stream. On encountering a filename of the form scheme://..., PHP assumes this is a URL and searches for a protocol handler for that scheme; if no such handlers are registered, PHP emits a notice and continues as if filename specifies a regular file. If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled; if disabled, PHP will emit a warning and the fopen() call will fail. If PHP has decided that filename specifies a local file, it will try to open a stream on that file. fopen(filename, mode, use_include_path [optional parameter], resource_context [optional parameter]);

[The optional use_include_path parameter can be set to 1 or TRUE if you want to search for the file in the include_path too. The following values can be used for the mode parameter: r; r+; w; w+; a; a+; x; x+; c; c+; e; b [forces binary mode, which will not translate your data]; and t [a Windows-offered text-translation mode which translates line-endings appropriately for the Windows platform]. It is recommended to always use the b flag for portability reasons.]

fopen(): returns a file pointer resource on success; FALSE and a suppressable[-with-@] E_WARNING on failure. When connecting to a Microsoft IIS server using SSL, IIS will violate the protocol by closing the connection without sending a close_notify indicator. For PHP to work around this, error_reporting should be lowered to a level that does not include warnings. When using the https:// wrapper, PHP will suppress the warnings. If using fsockopen() to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning.
fpassthru()

[fpassthru – Output all remaining data on a file pointer]

This function reads from the current position to the end of the file_pointer [‘passes through’] and writes the results to the output buffer. If you have already written data to the file, you may need to call rewind() to reset file_pointer to the beginning of the file. To simply dump the contents of a file to the output buffer without first modifying it/seeking to a particular offset, the readfile() function might be more efficient (since it doesn’t require the fopen() call). fpassthru(file_pointer); fpassthru(): returns the number of characters read from file_pointer and passed through to the output on success; FALSE on failure.
fputcsv()

[fputcsv – Format line as CSV and write to file pointer]

This function formats a line – passed as a fields array – as CSV and writes it [‘puts it’] (terminated by a newline) to file_pointer. fputcsv(file_pointer, fields, delimiter [optional single-character parameter with a default value of “,“], enclosure [optional single-character parameter with a default value of ‘“”‘], escape_char [optional single-character parameter with a default value of “\“]); fputcsv(): returns the length of the written string on success; FALSE on failure.
fread()

[fread – Binary-safe file read]

This function reads up to length bytes from file_pointer.
Reading stops as soon as: 1.) length bytes have been read; OR 2.) end-of-file is reached; OR 3.) a packet becomes available or a socket_timeout occurs; OR 4.) if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made – depending on the previously buffered data, the size of the returned data may be larger than the chunk size.
fread(file_pointer, length); fread(): returns the read string on success; FALSE on failure. The file must be opened with ‘b’ included in the fopen() mode parameter on systems that differentiate between binary and text files. Reading starts from the current position in the file_pointer; this position is specified by the ftell() function. Reading stops when a packet becomes available on streams returned when reading remote files, or when using popen() or fsockopen().

Web design certified by:
Click images for proof of certification.


Exit mobile version