在Fat-Free Framework中重命名后如何获取上载的文件名?

时间:2019-03-27 10:40:27

标签: fat-free-framework

我用它来保存上传的文件

$web = \Web::instance();

$uploadPath=$f3->get('uploadFolder');
$f3->set('UPLOADS',$uploadPath);

$overwrite = true;
$slug = true;

$files = $web->receive(function($file,$formFieldName){

        if(file_exists($file['name'])){
            //$file['name'] = $f3->get('uploadFolder').'rename.jpg'; // this is error, how to get path from config.ini here?
            $file['name'] = 'assets/img/upload/rename.jpg';
            move_uploaded_file($file['tmp_name'], $file['name']);
            return false;
        }else{
            return true;
        }
    },
    $overwrite,
    $slug
);

$savedFile=array_keys($files)[0];

这仅在重命名之前获取文件路径,如何在重命名之后获取路径?

以及如何在回调函数中获取配置?

1 个答案:

答案 0 :(得分:0)

您不需要从config获取任何上载目录,也不需要自己手动调用move_uploaded_file。这就是$web->receive方法的一部分。

$files数组将包含完整的最终路径(包括重命名的文件名)。

当您在回调函数中返回true时,上传的文件将移动到UPLOADS F3变量中定义的上传文件夹中。如果需要,只需在回调函数中检查文件大小,mime类型等。这就是您通常需要做的。

相关问题