Tp5 SplFileObject::__construct(/tmp/phpvuOdFd): failed to open stream: No such file or director解决方法

简介: Tp5 SplFileObject::__construct(/tmp/phpvuOdFd): failed to open stream: No such file or director解决方法

在使用一个后端框架接收3个图片后上传后,3个file文件域,报错:

解决办法:

分别接收文件,最后上传方法(从update往下)

public function update($id)
    {
        $data = input('post.');
        // 接收的数据为空
        $data["pet_src1"]="";
        $data["pet_src2"]="";
        $data["pet_src3"]="";
        if (isset($_FILES['pet_src1']) && $_FILES['pet_src1']['error'] == 0){
$pet_src1 = request()->file('pet_src1');
}
if (isset($_FILES['pet_src2']) && $_FILES['pet_src2']['error'] == 0){
$pet_src2 = request()->file('pet_src2');
}
if (isset($_FILES['pet_src3']) && $_FILES['pet_src3']['error'] == 0){
$pet_src3 = request()->file('pet_src3');
}
if(isset($pet_src1)){
$data['pet_src1'] = $this->upload_file($pet_src1);
}
if(isset($pet_src2)){
$data['pet_src2'] = $this->upload_file($pet_src2);
}
if(isset($pet_src3)){
$data['pet_src3'] = $this->upload_file($pet_src3);
}
        var_dump($data);
    }
   public function upload_file($file){
    // $file = request()->file('image');//这里就不要了
        if($file){
            //将传入的图片移动到框架应用根目录/public/uploads/ 目录下,ROOT_PATH是根目录下,DS是代表斜杠 / 
            $info = $file->move(ROOT_PATH . 'public' . DS .'uploads'. DS );
            if($info){
                  return $info->getSaveName();
            }else{
                // 上传失败获取错误信息
                return $file->getError();
            }
        }
        else{
             die(
        json_encode(
            array(
            'code' => 100,
            'data' => '',
            'msg' => '参数错误或没有图片信息'
        ),480)
);
        }
    }

打印成功解决

相关文章
|
7月前
|
前端开发
【前端异常】Module build failed: Error: ENOENT: no such file or directory, scandir ‘G:\OPWeb\public\node_m
【前端异常】Module build failed: Error: ENOENT: no such file or directory, scandir ‘G:\OPWeb\public\node_m
69 0
|
5月前
DevTools failed to load source map: Could not load content for…System error: net::ERR_FILE_NOT_FOUN
DevTools failed to load source map: Could not load content for…System error: net::ERR_FILE_NOT_FOUN
|
应用服务中间件 nginx
[error] OpenEvent(“Global\ngx_reload_11812“) failed (2: The system cannot find the file specified
[error] OpenEvent(“Global\ngx_reload_11812“) failed (2: The system cannot find the file specified
torch.distributed.init_process_group(‘gloo’, init_method=‘file://tmp/somefile’, rank=0, world_size=1
torch.distributed.init_process_group(‘gloo’, init_method=‘file://tmp/somefile’, rank=0, world_size=1
537 0
torch.distributed.init_process_group(‘gloo’, init_method=‘file://tmp/somefile’, rank=0, world_size=1
open函数: 可以帮助我们获取文件对象 内置函数 open(file, mode='r', buffering=-1, encoding=None, errors=None
open函数: 可以帮助我们获取文件对象 内置函数 open(file, mode='r', buffering=-1, encoding=None, errors=None