ONO::IO is responsible for all file and directory accesses, as long as they are located within the ONO document root directory. All I/O should either be handled by ONO::IO, or by ONO::Core::HostIO, you should not use low level Perl I/O stuff in your ONO projects.
Important I/O calls include:
ONO::IO also allows to manage cache and configuration files for example:
Most ONO::IO calls respect the presence of thumbnail and preview files, those can also be detected if necessary:
Furthermore, the module offers access to system information and allows for system interaction:
ONO::IO also helps with software development, by detecting development stations and offering appropriate tools, for example:
For file and directory I/O outside of the ONO document root, see ONO::Core::HostIO.
Append data to a file, data can be a string or an array.
Return the software base (if cgi-bin is not on the document root level, as in www.example.com/path/lang/cgi-bin/... for example). Note that the base always needs to be composed of 2 subdirectories.
List UNIX directories that may contain useful UNIX binaries that can be used by certain ONO::Lib modules for example.
Removes a cache file.
Note that empty dirs in /var/tmp/cache are not being removed, which means that some sort of garbage collection will be required some day...
Check if a cache entry exists (returns 1 if yes, or 0 if not).
Turn a file (directory/path plus filename) into a cache ID filename. This is usually not required, but it's used internally by other cache related functions.
Simplified form of cachelist(), simple and fast, supplies no useful info, just returns the content of the cache, doesn't automatically manage or delete anything by itself.
Read a cache file, and do some cache management at the same time.
If $time is provided, then we'll only read the cache if it's not older than T minutes. if it's older, then the cache file will simply be removed.
Switches:
If no options and no cache management is required, then cachereadsimple() will be a better and faster option here.
Simplified form of cacheread(), simple and fast, supplies no useful info, just returns the content of the cache, doesn't automatically manage or delete anything by itself.
Get the timestamp of a cache file, which may be useful to decide if it's time to remove or replace it.
Write a cache file, and do some cache management at the same time.
Switches:
If no options and no cache management is required, then cachewritesimple() will be a better and faster option here.
Simplified form of cachewrite(), simple and fast, doesn't do anything special. Just writes the data, doesn't automatically manage or delete anything by itself.
Change file or directory permissions.
Similar to list(), but removes all carriage returns, lewlines and tabs.
The cleanup() function will remove all special characters form a filename, directory name, or a path. The override option may be used for any data stored within the /servers tree.
This will simply close a file handle. Also see open().
This allows to quickly read files in name:value list format, data will be returned in hash format.
Same as project().
Compare files.
Returns NULL if files are identical Returns difference details if NOT identical
$max: if file bigger than $max then only check file size (no diff)
$fast: avoid using diff if possible, does not always return differences though
Read an ONO configuration file.
Switches:
Update an ONO configuration file, which replaces the $value of the $name entry. The remaining data will not be touched.
Write an ONO configuration file. This is basically the same as the store() function, which means that YOU will need to take care of formatting the data before sending it.
Create a copy of of filename.ext, at the same location. The new file will be named filename_copy.ext. If filename_copy.ext exists, the name will become filename_copy_X.ext, where X is a number starting at 1.
If present, thumbnails will also be copied.
Count objects (directories and files) inside a directory. Note that this does NOT work recursively, only the first level of the directory is being taken into consideration.
Switches:
Copy a file to a new target. Related thumbnails and setup files will also be taken into consideration.
Recursively copy a directory.
Switches:
Return CPU info. This should display the type of processor, as well as the number of available cores (multithreading is being considered).
An intelligent version of "store" that will not overwrite existing files, but add a number to the filename, if the file already exists.
Retrieve a file from the web, return the data as a stream. Be careful not to pass the input unchecked, and don't allow user input to be passed to this function!
Same as curl(), but dump / store the data into a file.
Append to /__debug.txt. This should not be used on production systems, but only on development stations. It may be used temporarely on production systems to analyze problems that need a quick fix, but make sure to remove /debug.txt later on then.
Turns 'ABCXYZ' into 'A/AB/ABC'.
Turns 'ABCXYZ' into ('A','AB','ABC').
Write to /__devdump.txt if we're on a devstation, so this can be used for debugging purposes. The file will be overwritten each time, so this should be used at the end of the script. Date and time will be automatically added to the top of the content.
If we're on a devstation, then guess the absolute URI, based on the name of the input script. This can be use useful to debug links.
Return the type of device in use.
3 ways to use this:
device() will return either computer, tablet or phone
device(type) will return either 0 or 1
device("useragent") will return the user agent
iPad Warning:
Note that current iPads identify themselves as Intel Macs. A dirty trick is needed to identify them correcty: 1. First test if it's a Mac, using ONO;;IO->device("mac") 2. The use if (navigator.maxTouchPoints > 1) {...} to execute JS
Return content only if we're in devstation mode. This allows to print debugging info on a web page on a development station, this info will not be displayed on production systems for example. Args(int): disable, replace return/linefeed by HTML br, bold
This will return 1 if we're on a devstation, or 0 if we're on a production system. This will only work if...
... we're in a local network and a file named /cgi-bin/devstation.txt is available, or ...
... the file /mnt/ono/cgi-bin/devstation.txt is present on the UNIX root level.
Note that the devstation.txt file should contain the devstation client's IP address as content.
Only refresh if devstation - probably deprecated ?
Like store, but will only execute on a devstation, which may be useful when debugging code.
List dirs and files.
Switches:
Note that the RX modes will ONLY list directories, NOT files!
Is this a directory (returns 'dir') or a file (returns 'file') ?
Extensions that will always be treated as files, even if they're dirs.
Protect a directory by putting an index.shtml into it. This will still allow access to files within the directory, but listing it will be prohibited. Also see htaccess() for additional protection.
Return the size of a directory (including all files and directories contained in it).
Switches:
List hard drives, display disk usage (percentage).
Return the domain, remove stuff like 'www' and other subdomains.
Return the domain, including 'www' or subdomains for example. The domain can also be set via a configuration file (etc/domain.conf), which may be required in some proxy environments.
Dump data to a file, without any processing. Use this only if store() stoesn't work for some reason. This may be used to store uploaded files containing special data for example.
Dump data to a file, without any processing. Use this only if append() stoesn't work for some reason.
Load an entire file, return as string, don't process anything. Use this only if load() stoesn't work for some reason.
Execure a UNIX command, via ONO::Core::Kernel's exec() function.
Execure a UNIX command. This is a less restrictive version of exec() (allows (\',\",\@,\:,\[,\])).
Execure a UNIX command. This is a zero restrictions version of exec (allows everything) THIS MAY BE DANGEROUS TO USE - especially if you're using it in a script that's running with root privileges.
Check if file or path exists. Returns 1 if exists, or nothing if the object doesn't exist.
Wait until a file has been created, which is useful if complex file generation tools are being used. Waiting for up to 3 secs is default, higher values can be set manually.
Extensions used by files that are actually not files, but dirs
Transform /my/path/to/file.ext into /my/path/to/.
Only works correctly if the input is using a correct /my/path/to/file.ext format.
Transform /my/path/to/file.ext into ('/my/path/to/','file.ext').
Only works correctly if the input is using a correct /my/path/to/file.ext format.
Return the file and its extension, eg file.ext becomes ('file','ext').
Return file type: image, audio, video or pdf. Will be empty if it's none of those.
Replace an image URL into a preview or thumbnail URL if the required files exist, and if the image dimensions are adequate.
Returns the path to an optional setup file.
Switches:
Returns paths to preview and thumbnail files. Returns nothing if the file type does not allow for thumbnail files.
Returns paths to preview and thumbnail files, but onyl if they exist, and if the file type supports them.
Return file data as a hash. This works for lists separated by semicolon.
Write a hash to a file, using semicolon separation. Input needs to be a hash reference in this case.
Password management and protection only. See dirprotect to prevent directory listing.
You need to specify $key, if this is empty then the protection will be removed. To protect without any login option, simply use ':' as $key.
Restrict access to a directory only for one IP address.
Add a rewrite rule via .htaccess, simply indicate the target, which must be a path to a script.
Encode a string by replacing HTML lt, gt and quot. This will be useful in input fields for example.
Returns 'http' or 'https', depending on the current SSL status of the domain.
Returns http(s)://www.example.com/ono/path/. This basically glues the http(), domain() and base() functions.
Returns 1 if SSL is available, or 0 is SSL is not available. Returning 1 can be forced, by adding a dedicated setup file (etc/https.conf), which may be required in certain proxy environments.
Returns 1 if file extension is image, or 0 if not. This works for both filenames, and directory/filename combinations.
Return a list of common (not all) image extensions.
Same as image(), but does not work for preview and thumbnail files.
Filter and return input, by removing a number of special characters
Like inputfilter(), but for arrays.
Return the IP address of the host.
Is the provided IP a local IP ? Returns 1 of local, or 0 if not local. Also see local().
Not to be confused with local(), which tells you if the host's IP is local.
List a file. Similar to load(), but returns lines as an array.
Switches:
Like list(), but returns only one specific line from the file, which must be indicated as a number.
List_raw() is identical to list(), but allows to load files without checking the file name, which means that it also loads files with special characters.
Load a file, return its content.
Switches:
Are we in a local network? Returns 1 = yes, 0 = no. This will only work if the SERVER_NAME is an IP address, not a domain, unless the domain will be of type example.local.
Same as dir().
List directory items by timestamp. This will simply dump the UNIX ls output.
Return the total amount of RAM available, in GB / GigaBytes.
Create a new directory. Permissions may be set at the same time. Also see mkpath() for a more powerful alternative.
This will create a new subdir, add a number if such a subdir already exists, and return the created name. The new subdir will always have permissions set to 777.
Like mkdir(), but generates the entire path, including all of its subdirs. Permissions may be set at the same time.
Move or rename a file or a directory. Related thumbnails and setup files will also be taken into consideration.
Like mv(), but for "dirty" sources containing bad characters. Related thumbnails and setup files will also be taken into consideration.
Return the type of a object:
'none' if object doesn't exist 'dir' if object is a directory 'file' if object is a file
Also see dirfile(), which does more or less the same thing (only the 'none' option is missing), only better.
This will simply open a file handle, as required by ONO_Lib_Image_Check for example. Also see close().
Return the OS of the host ('linux' or 'macos'). This is similar to ONO::Core::HostOS->host_os(), although the output is different.
Returns the UNIX path to the ONO document root directory. This is the same as ONO::Core::Kernel->vpath, so you may simply get this info via ONO::IO.
Demove everything behind the last slash (including the last slash itself). This will remove any file info from the directory and return the pure directory path.
Also see getdir(), getdirfile(), and getdirfileext(), which will be more useful in most cases.
Returns a pixel image as a data stream.
Return the name of an ONO project, as in www.example.com/cgi-bin/local/perl/project_name/... for example.
Return file as content as an array, without doing anything else.
Read a setup file.
HTML refresh, this will simply auto-redirect to a different page. In most cases, you will simply push refresh($url) to the client.
You may specify seconds to wait, and you may also force using SSL/https for the destination.
For testing purposes, the 'auto' feature is disabled on development stations, which will display a clickable link displaying the entire URL instead. Using $devstation_overrule will override this behaviour and enable the 'auto' features on development stations too.
Renumber files and/or directories in a directory, shtml/setup files as well as pt/tn files will be ignored. Note that all thumbs and previews will be removed during this process.
Remove (aka delete) a file, including its (optional) thumbnails and setup files.
Remove directory, including all of its contents. Recursive and with force delete enabled, use rmdirsoft() for a less dangerous operation.
Like rmdir(), but without force.
Like rm(), but a special version that will additionally remove the file with multiple possible image extensions.
Save / store a setup file.
Return the size of a file, by default this will simply return the number of bytes.
Switches:
Split a file into pieces.
Returns file or directory stats as an array.
Store a file. If the file exists, it will be overwritten. Data can be a string, or an array.
Store a file if data is provided (just like store()), remove the file if data is empty. Unlinke store(), data cannot be an array, online strings are supported.
Create a symlink.
Direct access to the UNIX system, via ONO::Core::Kernel's sys() function.
Returns the current system load (percent of total available), CPU cores and multithreading are taken into consideration.
This can be used to run or disable code depending on the system load of the host, sysload(50) is true if current load is LOWER than 50 for examaple.
This uses cached system load info, which will be updated about every 5 seconds.
Note that the threshold feature is NOT working on development stations, which makes developing under high load conditions a lot easier (devstations always return 1).
Returns a system overload message. Note that this function only dumps some text, it does not do or detect anything. It may be a good idea to use this in combination with sysload().
Return the modification (or creation) timestamp of a file or directory.
Update the modification timestamp of a file or directory.
This is a file or a directory? Returns 'dir' or 'file'. Please use dirfile() instead, or objtype(), which do the same thing.
Return the host's uname string, which offers some host system information.
Remove a symlink.
Unzip a file or directory.
CGI upload, which allows single file upload directly via ONO::IO. In most cases, you will avoid this and use ONO::ToolBox::Upload and ONO::Lib::Web::Upload instead.
$max = file size limit (absolute limit = 4 MB)
Returns the rawdata.pl upload script URL.
Find a UNIX binary. Accepts the binary name as input, returns the path to the binary.
Get / extract XML data. This only works for very simple XML files, and it will only return the first instance of the data.
Compress a file. Warning: gzip only works with single files, use 'tar' to zip entire directories
Do NOT use this routine if possible, we recommend using the simple 'dir' with option -R instead note that this routine ignores hidden files and folders, and it does not support directories with dots in their names (which would be ONO-incompatible anyway).
Do NOT use this routine if possible, we recommend using the simple 'dir' with option -RX instead