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)
);
        }
    }

打印成功解决

相关文章
成功解决:Failed to load resource: net::ERR_FILE_NOT_FOUND
这篇文章提供了解决"Failed to load resource: net::ERR_FILE_NOT_FOUND"错误的步骤,通过修改配置文件中的资源路径设置为相对路径"./"来成功运行打包后的项目。
成功解决:Failed to load resource: net::ERR_FILE_NOT_FOUND
Flutter之运行提示Could not update files on device: Connection closed before full header was received
Flutter之运行提示Could not update files on device: Connection closed before full header was received
748 0
|
11月前
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
|
TensorFlow 算法框架/工具 Python
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
Jmeter问题之:解决 Cannot send data to network connection
Jmeter问题之:解决 Cannot send data to network connection
248 0
Jmeter问题之:解决 Cannot send data to network connection
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
602 0
torch.distributed.init_process_group(‘gloo’, init_method=‘file://tmp/somefile’, rank=0, world_size=1