Documentation

Upload extends SimpleModel
in package
Uses Upload

Upload table stores info about files that have been uploaded.

..

Tags
psalm-suppress

UnusedClass

Table of Contents

addData()  : void
Hook for adding extra data to a file save.
canaccess()  : bool
Determine if a user can access the file
delete()  : void
Automatically called by RedBean when you try to trash an upload. Do any cleanup in here
downloaded()  : void
Hook for doing something when a file is downloaded
fail()  : void
Generate an error message
link()  : string
Return the value need for an HREF on a download <a> tag
owner()  : object|null
Return the owner of this uplaod
replace()  : void
Replace the existing uploaded file with another one
savefile()  : bool
Store a file
updateData()  : void
Hook for adding extra data to a file replace.
mkch()  : void
Make a directory if necessary and cd into it
mkpath()  : array<string|int, mixed>
Make a path for a new file

Methods

addData()

Hook for adding extra data to a file save.

public addData(Context $context, int $index) : void
Parameters
$context : Context

The context object for the site

$index : int

If you are reading data from an array fo files, this is the index in the file. You may have paralleld data arrays and need this index.

Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
void

canaccess()

Determine if a user can access the file

public canaccess(OODBBean $user[, string $op = 'r' ]) : bool

At the moment it is either the user or any admin that is allowed. Rewrite the method to add more complex access control schemes.

Parameters
$user : OODBBean

A user object

$op : string = 'r'

r for read, u for update, d for delete

Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
bool

delete()

Automatically called by RedBean when you try to trash an upload. Do any cleanup in here

public delete() : void
Tags
throws
Forbidden
Return values
void

downloaded()

Hook for doing something when a file is downloaded

public downloaded(Context $context) : void
Parameters
$context : Context

The context object for the site

Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
void

fail()

Generate an error message

public static fail(Context $context, array<string|int, mixed> $fa) : void
Parameters
$context : Context
$fa : array<string|int, mixed>
Return values
void

Return the value need for an HREF on a download <a> tag

public link() : string
Return values
string

owner()

Return the owner of this uplaod

public owner() : object|null
Return values
object|null

replace()

Replace the existing uploaded file with another one

public replace(Context $context, array<string|int, mixed> $da, int $index) : void
Parameters
$context : Context
$da : array<string|int, mixed>

The file upload info array via a FormData('file')

$index : int

The index if this all part of an array of data

Tags
throws
InternalError
Return values
void

savefile()

Store a file

public savefile(Context $context, array<string|int, mixed> $da, bool $public[, OODBBean|null $owner = NULL ], int $index) : bool

This is the basic functionality assumed by the framework. You can adapt this by changing this function. Best though if you only add functionality :-)

Parameters
$context : Context

The context object for the site

$da : array<string|int, mixed>

The relevant $_FILES element (or similar generated by FormData)

$public : bool

If TRUE then store in the public directory

$owner : OODBBean|null = NULL

The user who owns the upload. If NULL then the currently logged in user

$index : int

If there is an array of files possibly with other data, then this is the index in the array.

Tags
throws
InternalError
Return values
bool

updateData()

Hook for adding extra data to a file replace.

public updateData(Context $context, int $index) : void
Parameters
$context : Context

The context object for the site

$index : int

If you are reading data from an array of files, this is the index in the file. You may have parallel data arrays and need this index.

Tags
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
void

mkch()

Make a directory if necessary and cd into it

private static mkch(string $dir) : void
Parameters
$dir : string

The directory name

Tags
throws
Forbidden
Return values
void

mkpath()

Make a path for a new file

private mkpath(Context $context, object|null $owner, bool $public, array<string|int, mixed> $da) : array<string|int, mixed>
Parameters
$context : Context
$owner : object|null
$public : bool
$da : array<string|int, mixed>
Return values
array<string|int, mixed>

Search results