Neos\Flow\ResourceManagement\ResourceManager::prepareUploadedFileForImport PHP Method

prepareUploadedFileForImport() protected method

Prepare an uploaded file to be imported as resource object. Will check the validity of the file, move it outside of upload folder if open_basedir is enabled and check the filename.
protected prepareUploadedFileForImport ( array $uploadInfo ) : array
$uploadInfo array
return array Array of string with the two keys "filepath" (the path to get the filecontent from) and "filename" the filename of the originally uploaded file.
    protected function prepareUploadedFileForImport(array $uploadInfo)
    {
        $openBasedirEnabled = (bool) ini_get('open_basedir');
        $temporaryTargetPathAndFilename = $uploadInfo['tmp_name'];
        $pathInfo = UnicodeFunctions::pathinfo($uploadInfo['name']);
        if (!is_uploaded_file($temporaryTargetPathAndFilename)) {
            throw new Exception('The given upload file "' . strip_tags($pathInfo['basename']) . '" was not uploaded through PHP. As it could pose a security risk it cannot be imported.', 1422461503);
        }
        if (isset($pathInfo['extension']) && array_key_exists(strtolower($pathInfo['extension']), $this->settings['resource']['uploadExtensionBlacklist']) && $this->settings['resource']['uploadExtensionBlacklist'][strtolower($pathInfo['extension'])] === true) {
            throw new Exception('The extension of the given upload file "' . strip_tags($pathInfo['basename']) . '" is blacklisted. As it could pose a security risk it cannot be imported.', 1447148472);
        }
        if ($openBasedirEnabled === true) {
            // Move uploaded file to a readable folder before trying to read sha1 value of file
            $newTemporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'ResourceUpload.' . uniqid() . '.tmp';
            if (move_uploaded_file($temporaryTargetPathAndFilename, $newTemporaryTargetPathAndFilename) === false) {
                throw new Exception(sprintf('The uploaded file "%s" could not be moved to the temporary location "%s".', $temporaryTargetPathAndFilename, $newTemporaryTargetPathAndFilename), 1375199056);
            }
            $temporaryTargetPathAndFilename = $newTemporaryTargetPathAndFilename;
        }
        if (!is_file($temporaryTargetPathAndFilename)) {
            throw new Exception(sprintf('The temporary file "%s" of the file upload does not exist (anymore).', $temporaryTargetPathAndFilename), 1375198998);
        }
        return ['filepath' => $temporaryTargetPathAndFilename, 'filename' => $pathInfo['basename']];
    }