thinkphp在linux下获取文件大小报错 SplFileInfo::getSize(): stat failed for /tmp/phpSR7Dm1 thinkphp5在win下上传图片并获取图片SIZE可以使用,但是代码上传到ubuntu下报错 `SplFileInfo::getSize(): stat failed for /tmp/phpSR7Dm1` 开始怀疑是linux下需要安装拓展GD库,但是查看后发现不是这个原因, 后来尝试在文件上传之前获取size,发现问题解决了。 ```php $file = request()->file('image'); if(empty($file) || !in_array(input('type'), array('fields'))){ return $this->err('参数错误!'); } $size = $file->getSize();//错误原因在这里,原来是在move()后执行,在之前执行解决问题。 $valid['size'] = 2097152;//2M $valid['ext'] = 'jpg,png,gif'; $path = config('APP_FILE_PATH').'http://static.chenls.me/chenls/uploads/'.input('type').'/'; $info = $file->validate($valid)->rule('date')->move($path); if($info){ $fileUrl = $path.$info->getSaveName(); $image = \think\Image::open($fileUrl); //水印 if(input('isWatermark') == 1){ $attData['is_watermark'] = 1; $image->text(self::$weter,'./static/hplus/fonts/HYQingKongTiJ.ttf',$image->height() * 0.08,'#ffffff',9,-10)->save($path.$info->getSaveName()); } $reback['url'] = str_replace(config('APP_FILE_PATH'),"",$fileUrl); $attData['url'] = $reback['url']; $attData['storage'] = 'local'; $attData['imagewidth'] = $image->width(); $attData['imageheight'] = $image->height(); $attData['filesize'] = $size/1024; $attData['imagetype'] = $image->type(); $attData['mimetype'] = $image->mime(); $Attachment->save($attData); return $this->suc($reback); }else{ return $this->err($file->getError()); } ```