class BlobUtil

Constants

BAD_FILE_SUFFIXES

Methods

static 
emptyPostSessionLost()

Check to see if the $_POST is completely broken in file upload Sometimes, if the maxUpload_SIZE is exceeded, it deletes all of $_POST and we lose our session.

static 
emptyPost()

Check to see if the $_POST is completely broken in file upload Sometimes, if the maxUpload_SIZE is exceeded, it deletes all of $_POST

static 
uploadTooLarge($filename)

No description

static 
getFolderName()

No description

static 
fixFileName($name)

No description

static 
safeFileSuffix($filename)

No description

static 
validateUpload($FILE_DESCRIPTOR, $SAFETY_CHECK = true)

Returns true if this is a good upload, an error string if not

static 
checkFileSafety($FILE_DESCRIPTOR, $CONTENT_TYPES = array("image/png", "image/jpeg"))

No description

static 
isPngOrJpeg($FILE_DESCRIPTOR)

Make sure the contents of this file are a PNG or JPEG

static 
getBlobFolder($sha_256, $blob_root = false)

No description

static 
mkdirSha256($sha_256, $blob_root = false)

No description

static 
uploadToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK = true, $backref = null)

uploadToBlob - returns blob_id or false

static 
isTestKey($key)

isTestKey - Indicate if this is a key that is supposed to stay in blob_file

static 
uploadFileToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK = true, $backref = null)

Legacy code - returns array [id, sha256]

static 
setBackref($file_id, $backref)

Set the backref for a file entry

static 
uploadPathToBlob($filename, $content_type, $backref = null)

Read a file off local disk and put it into a blob

static 
uploadFileToString($FILE_DESCRIPTOR)

No description

static 
deleteBlob($file_id, $admin_bypass = false)

Delete a blob based on its id

static 
getAccessUrlForBlob($blob_id, $serv_file = false)

No description

static 
maxUpload()

No description

static 
maxUploadBytes()

No description

static 
return_bytes($val)

No description

static mixed
migrate($file_id, $test_key = false)

Check and migrate a blob from an old place to the right new place

static mixed
blob2blob($file_id)

Check and migrate a blob from blob_file to blob_blob

static mixed
blob2file($file_id)

Check and migrate a blob to its corresponding file

Details

at line 15
static emptyPostSessionLost()

Check to see if the $_POST is completely broken in file upload Sometimes, if the maxUpload_SIZE is exceeded, it deletes all of $_POST and we lose our session.

at line 24
static emptyPost()

Check to see if the $_POST is completely broken in file upload Sometimes, if the maxUpload_SIZE is exceeded, it deletes all of $_POST

at line 32
static uploadTooLarge($filename)

Parameters

$filename

at line 37
static getFolderName()

at line 50
static fixFileName($name)

Parameters

$name

at line 65
static safeFileSuffix($filename)

Parameters

$filename

at line 74
static validateUpload($FILE_DESCRIPTOR, $SAFETY_CHECK = true)

Returns true if this is a good upload, an error string if not

Parameters

$FILE_DESCRIPTOR
$SAFETY_CHECK

at line 95
static checkFileSafety($FILE_DESCRIPTOR, $CONTENT_TYPES = array("image/png", "image/jpeg"))

Parameters

$FILE_DESCRIPTOR
$CONTENT_TYPES

at line 112
static isPngOrJpeg($FILE_DESCRIPTOR)

Make sure the contents of this file are a PNG or JPEG

Parameters

$FILE_DESCRIPTOR

at line 123
static getBlobFolder($sha_256, $blob_root = false)

Parameters

$sha_256
$blob_root

at line 140
static mkdirSha256($sha_256, $blob_root = false)

Parameters

$sha_256
$blob_root

at line 172
static uploadToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK = true, $backref = null)

uploadToBlob - returns blob_id or false

Returns false for any number of failures, for better detail, use validateUpload() before calling this to do the actual upload.

Parameters

$FILE_DESCRIPTOR
$SAFETY_CHECK
$backref

at line 182
static isTestKey($key)

isTestKey - Indicate if this is a key that is supposed to stay in blob_file

Parameters

$key

at line 206
static uploadFileToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK = true, $backref = null)

Legacy code - returns array [id, sha256]

Returns false for any number of failures, for better detail, use validateUpload() before calling this to do the actual upload.

Parameters

$FILE_DESCRIPTOR
$SAFETY_CHECK
$backref

at line 319
static setBackref($file_id, $backref)

Set the backref for a file entry

This is a soft foreign key in the frorm of:

table:column:value peer_submit::submit_id::2

This is uses when we want to link a blob to a record at an even finer level than context_id and link_id which is done by default.

When an application is doing a two-phase commit where it is uploading the file and then creating the record in the table that references the file (i.e. peer_submit in the above example), it can set the back ref to have a value of -1 to indicate that the file is as yet unlinked

peer_submit::submit_id::-1

and then once the peer_submit record is committed call this routine to point to the real record in the table.

Parameters

$file_id
$backref

at line 337
static uploadPathToBlob($filename, $content_type, $backref = null)

Read a file off local disk and put it into a blob

Parameters

$filename
$content_type
$backref

at line 418
static uploadFileToString($FILE_DESCRIPTOR)

Parameters

$FILE_DESCRIPTOR

at line 446
static deleteBlob($file_id, $admin_bypass = false)

Delete a blob based on its id

This cleans up files from the file table and if there are no more references to the file, eliminates the blob. This can only delete blobs in the current CONTEXT - but ultimately it is up to the calling code to decide who (i.e. an instructor) is allowed to delete a file.

Parameters

$file_id The file to delete
$admin_bypass Run outside the context of a launch

at line 514
static getAccessUrlForBlob($blob_id, $serv_file = false)

Parameters

$blob_id
$serv_file

at line 523
static maxUpload()

at line 534
static maxUploadBytes()

at line 552
static return_bytes($val)

Parameters

$val

at line 590
static mixed migrate($file_id, $test_key = false)

Check and migrate a blob from an old place to the right new place

Parameters

$file_id
$test_key

Return Value

mixed true if the file was migrated, false if the file was not migrated, and a string if an error was enountered

at line 612
static mixed blob2blob($file_id)

Check and migrate a blob from blob_file to blob_blob

Parameters

$file_id

Return Value

mixed true if the file was migrated, false if the file was not migrated, and a string if an error was enountered

at line 696
static mixed blob2file($file_id)

Check and migrate a blob to its corresponding file

Parameters

$file_id

Return Value

mixed true if the file was migrated, false if the file was not migrated, and a string if an error was enountered