\apex\app\ioio

I/O Library for File and Directory Handling.

Service: apex\svc\io

This class contains various methods to aid in managing files and directories, plus allows for the sending of HTTP requests, and creation / unpacking of zip archives.

This class is available within the services container, meaning its methods can be accessed statically via the service singleton as shown below.

PHP Example

<?php

namespace apex;

use apex\app; use apex\svc\io;

// Create a directory io::create_dir($some_directory);

// Parse directory $files = io::parse_dir($some_dir);

Summary

Methods
Properties
Constants
parse_dir()
create_dir()
remove_dir()
send_http_request()
send_tor_request()
download_file()
generate_random_string()
execute_sqlfile()
create_zip_archive()
unpack_zip_archive()
get_chunk_upload()
send_chunked_file()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

parse_dir()

parse_dir(string  $rootdir, boolean  $return_dirs = false) : array

Parse a directory recursively, and return all files and/or directories.

Parameters

string $rootdir

The directory name / path to parse.

boolean $return_dirs

Whether or not to return directory names, or only filenames.

Returns

array —

An array of all resulting file / directory names.

create_dir()

create_dir(string  $dirname) 

Createa new directory recursively

Creates a directory recursively. Goes through the parent directories, and creates them as necessary if they do not exist.

Parameters

string $dirname

The directory to create.

remove_dir()

remove_dir(string  $dirname) 

Remove a directory

Removes a directory recursively. Goes through all files and sub-directories, and deletes them before deleting the parent directory.

Parameters

string $dirname

The directory name to delete.

send_http_request()

send_http_request(string  $url, string  $method = 'GET', array  $request = array(), string  $content_type = 'application/x-www-form-urlencoded', integer  $return_headers) : string

Send a remote HTTP request

Parameters

string $url

The full URL to send hte HTTP request to.

string $method

The method (GET/POST usually) of the request. Defaults to GET.

array $request

The request contents to send in array format.

string $content_type

THe content type of the request. Generally not needed, as the default works.

integer $return_headers

A 1 or 0 definine whether or not to return the HTTP readers of the response.

Returns

string —

Returns the response from the server.

send_tor_request()

send_tor_request(string  $url, string  $method = 'GET', array  $request = array(), string  $content_type = 'application/x-www-form-urlencoded', integer  $return_headers) : string

/ Send a remote HTTP request via the Tor network

Parameters

string $url

The full URL to send hte HTTP request to.

string $method

The method (GET/POST usually) of the request. Defaults to GET.

array $request

The request contents to send in array format.

string $content_type

THe content type of the request. Generally not needed, as the default works.

integer $return_headers

A 1 or 0 definine whether or not to return the HTTP readers of the response.

Returns

string —

Returns the response from the server.

download_file()

download_file(string  $url, string  $filename) : boolean

Download a remote file

Downloads a file from the given URL, and stories it within the specifiled filename. This streams the file into its target location to ensure there are no memory issues with larger files.

Parameters

string $url

The URL of the remote file to download.

string $filename

The filename to save the downloaded file to.

Returns

boolean —

WHther or not the operation was successful.

generate_random_string()

generate_random_string(integer  $length = 6, boolean  $include_chars = false) : string

Generate a random string.

Parameters

integer $length

The length of the random string.

boolean $include_chars

Whether or not to include special characters.

Returns

string —

The generated random string.

execute_sqlfile()

execute_sqlfile(string  $sqlfile) 

Execute SQL file

Parameters

string $sqlfile

The path to the SQL file to execute against the database

create_zip_archive()

create_zip_archive(string  $tmp_dir, string  $archive_file) 

Creates a new zip archive from the given directory name.

Parameters

string $tmp_dir

The directory to archive

string $archive_file

The location of the resulting archive file.

unpack_zip_archive()

unpack_zip_archive(string  $zip_file, string  $dirname) : boolean

Unpack a zip archive

Parameters

string $zip_file

The path to the .zip archive

string $dirname

The directory to create and unpack the archive to

Returns

boolean —

Whether or not the operation was successful.

get_chunk_upload()

get_chunk_upload(string  $file_id) 

Get a chunked file upload.

Will retrive a large file upload using chunks. Checks if upload is already in progress, and if so, appends to existing temporary file, otherwise starts a new upload and returns the filename. Once upload is done, will dispatch the 'core.fils. chunk_upload' event message to listner / workers.

Parameters

string $file_id

Any unique ID# that will be passed back to the listner / worker to identify the file upload completion.

send_chunked_file()

send_chunked_file(\apex\app\io\string  $url, string  $filename, string  $remote_filename) 

Send a chunked file

Parameters

\apex\app\io\string $url
string $filename

The full path of the file to send.

string $remote_filename

The remote filename to send with the request