示例#1
0
文件: saver.php 项目: akilli/qnd
/**
 * File saver
 *
 * @param array $attr
 * @param array $item
 *
 * @return bool
 */
function saver_file(array $attr, array &$item) : bool
{
    $item[$attr['id']] = null;
    $file = http_files('data')[$item['_id']][$attr['id']] ?? null;
    // Delete old file
    if (!empty($item['_old'][$attr['id']]) && ($file || !empty($item['_delete'][$attr['id']])) && !media_delete($item['_old'][$attr['id']])) {
        $item['_error'][$attr['id']] = _('Could not delete old file %s', $item['_old'][$attr['id']]);
        return false;
    }
    // No upload
    if (!$file) {
        return true;
    }
    $value = generator_file($file['name'], project_path('media'));
    // Upload failed
    if (!file_upload($file['tmp_name'], project_path('media', $value))) {
        $item['_error'][$attr['id']] = _('File upload failed');
        return false;
    }
    $item[$attr['id']] = $value;
    return true;
}
示例#2
0
文件: action.php 项目: akilli/qnd
/**
 * Project Import Action
 *
 * @return void
 */
function action_project_import() : void
{
    if (!($file = http_files('import'))) {
        message(_('No file to import'));
    } elseif ($file['ext'] === 'zip') {
        import_zip($file['tmp_name']);
    } elseif (in_array($file['ext'], ['html', 'odt'])) {
        $path = path('tmp', uniqid($file['name'], true));
        file_copy($file['tmp_name'], $path . '/' . $file['name']);
        import_page($path . '/' . $file['name']);
        file_delete($path);
    }
    redirect(url('*/admin'));
}
示例#3
0
文件: validator.php 项目: akilli/qnd
/**
 * File validator
 *
 * @param array $attr
 * @param array $item
 *
 * @return bool
 */
function validator_file(array $attr, array &$item) : bool
{
    $file = http_files('data')[$item['_id']][$attr['id']] ?? null;
    // Invalid file
    if ($file && empty(data('ext', $attr['type'])[$file['ext']])) {
        $item['_error'][$attr['id']] = _('Invalid file %s', $file);
        return false;
    }
    return true;
}