/program/main_file.php - workhorse for serving files
This file deals with serving files It is included and called from /file.php.
The work is done in main_file().
construct a zipfile with the current source and stream it to the visitor
this routine streams a ZIP-archive to the visitor with either the current websiteatschool program code or the selected manual. This routine is necessary to comply with the provisions of the program license which basically says that the source code of the running program must be made available.
Note that it is not strictly necessary to also provide the manual, but this routine can do that nevertheless.
Note that we take special care not to download the (private) data directory $CFG->datadir. Of course the datadirectory should live outside the document root and certainly outside the /program directory tree, but accidents will happen and we don't want to create a gaping security hole.
If there are severe errors (e.g. no manual is available for download or an invalid component was specified) the program exist immediately with a 404 not found error. Otherwise the ZIP-archive is streamed to the user. If all goes well, we return TRUE, if there were errors we immediately return TRUE (without finishing the task at hand other than a perhasp futile attempt to properly close the ZIP-archive). The last error message from the Zip is logged.
workhorse function to recursively add most of a tree to a ZIP-archive
this routine recursively adds the tree starting at $path to the opened archive $zip. If a directory is in the list of excluded directories in $excludes it is skipped.
exit with a 404 not found error
main program for serving files
this routine is called from /file.php.
This routine is responsible for serving files to the visitor. These files are stored in a (virtual) file hierarchy that looks like this.
/areas/areaname /another /stillmore ... /users/username /another /stillmore ... /groups/groupname /another /stillmore ... /websiteatschool/program /manual /languages
This structure maps to the real file system as follows. The (virtual) directories /areas, /users and /groups correspond to the fysical directories {$CFG->datadir}/areas, {$CFG->datadir}/users and {$CFG->datadir}/groups respectively. The subdirectories correspond to a (unique) area, user or group and serve as a file repository for that area, user or group.
The (virtual) top-level directory /websiteatschool is a special case. It is used to serve the currently running website program code and the user-defined translations of active languages.
Before any file is transmitted to the visitor the access privileges are checked. The following rules apply.
Access control for the /areas subdirectory
send a file to the visitor's browser in chunks
This sends the file $path to the browser in manageable chunks.
generate an RFC1123-compliant date/time stamp
This constructs a date/time stamp that is a fixed-length subset of RFC1123. This is the preferred format in HTTP (see RFC2616 section 3.3).
The format is as follows:
rfc1123-date = wkday "," SP date SP time SP "GMT" date = 2DIGIT SP month SP 4DIGIT ; day month year (e.g., 02 Jun 1982) time = 2DIGIT ":" 2DIGIT ":" 2DIGIT ; 00:00:00 - 23:59:59 wkday = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun" month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
If $timevalue is less or equal to zero, the current time is used, otherwies $timevalue is interpreted as a standard unix timestamp.
the designated file is sent to the visitor
This transmits the file {$CFG->datadir}$file from the data directory to the visitor's browser, suggesting the name $name. The file is transmitted in chunks (see readfile_chunked()).
Several different variations are possible.
Documentation generated on Tue, 28 Jun 2016 19:10:28 +0200 by phpDocumentor 1.4.0