class Importer (View source)

Constants

E_PHP_FILE_ERROR_DEFAULT

Standard PHP error: there is no error, the file uploaded with success.

E_PHP_FILE_EXCEEDS_UPLOAD_MAX_FILESIZE

Standard PHP error: the uploaded file exceeds the upload_max_filesize directive in php.ini.

E_PHP_FILE_EXCEEDS_HTML_MAX_FILE_SIZE

Standard PHP error: the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

E_PHP_FILE_PARTIAL_UPLOAD

Standard PHP error: the uploaded file was only partially uploaded.

E_PHP_NO_FILE

Standard PHP error: no file was uploaded.

E_PHP_NO_TMP_DIR

Standard PHP error: missing a temporary folder.

E_PHP_CANT_WRITE

Standard PHP error: failed to write file to disk.

E_PHP_EXTENSION

Standard PHP error: a PHP extension stopped the file upload.

E_FILE_INVALID_EXTENSION

concrete5 internal error: invalid file extension.

E_FILE_INVALID

concrete5 internal error: pointer is invalid file, is a directory, etc.

..

E_FILE_UNABLE_TO_STORE

concrete5 internal error: unable to copy file to storage location.

E_FILE_INVALID_STORAGE_LOCATION

concrete5 internal error: default file storage location not found.

E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED

concrete5 internal error: unable to copy file to storage location (with provided prefix).

E_FILE_EXCEEDS_POST_MAX_FILE_SIZE

concrete5 internal error: Uploaded file is too large.

Properties

protected bool $rescanThumbnailsOnImport

Should thumbnails be scanned when importing an image?

protected ProcessorInterface $importProcessors

The list of configured import processors.

protected Application $app

Methods

__construct()

No description

static string
getErrorMessage(int $code)

Returns a text string explaining the error that was passed.

addImportProcessor(ProcessorInterface $processor)

Add an import processor.

string
generatePrefix()

Generate a file prefix.

Version|int
import(string $pointer, string|bool $filename = false, File|FileFolder|null|false $fr = false, string|null $prefix = null)

Imports a local file into the system.

Version|int
importIncomingFile(string $filename, File|FileFolder|null|false $fr = false)

Import a file in the default file storage location's incoming directory.

Version|int
importUploadedFile(UploadedFile $uploadedFile = null, File|FileFolder|null|false $fr = false)

Import a file received via a POST request to the default file storage location.

setRescanThumbnailsOnImport(bool $refresh)

Enable scanning of thumbnails when importing an image?

Details

__construct()

No description

static string getErrorMessage(int $code)

Returns a text string explaining the error that was passed.

Parameters

int $code

Return Value

string

addImportProcessor(ProcessorInterface $processor)

Add an import processor.

Parameters

ProcessorInterface $processor

string generatePrefix()

Generate a file prefix.

Return Value

string

Version|int import(string $pointer, string|bool $filename = false, File|FileFolder|null|false $fr = false, string|null $prefix = null)

Imports a local file into the system.

Parameters

string $pointer

The path to the file

string|bool $filename

A custom name to give to the file. If not specified, we'll derive it from $pointer.

File|FileFolder|null|false $fr

If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).

string|null $prefix

the prefix to be used to store the file (if empty we'll generate a new prefix)

Return Value

Version|int

the imported file version (or an error code in case of problems)

Version|int importIncomingFile(string $filename, File|FileFolder|null|false $fr = false)

Import a file in the default file storage location's incoming directory.

Parameters

string $filename

the name of the file in the incoming directory

File|FileFolder|null|false $fr

If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).

Return Value

Version|int

the imported file version (or an error code in case of problems)

Version|int importUploadedFile(UploadedFile $uploadedFile = null, File|FileFolder|null|false $fr = false)

Import a file received via a POST request to the default file storage location.

Parameters

UploadedFile $uploadedFile

The uploaded file

File|FileFolder|null|false $fr

If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).

Return Value

Version|int

the imported file version (or an error code in case of problems)

Examples

<pre><code>
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$request = $app->make(\Concrete\Core\Http\Request::class);
$importer = $app->make(\Concrete\Core\File\Importer::class);
$fv = $importer->importUploadedFile($request->files->get('field_name'));
if (is_int($fv)) {
    $errorToShow = $importer->getErrorMessage($fv);
}
</code></pre>

setRescanThumbnailsOnImport(bool $refresh)

Enable scanning of thumbnails when importing an image?

Parameters

bool $refresh