下载文件，输出附件
@param  string $file 文件地址或者一段文字数据，当为文字数据时 isdata必须设置为true
@param  string $name 下载的文件名
@param  boolean $isdata 下载的是文件还是一段字符数据 默认是false 为文件
@return null
335445
public function file($file, $name = '', $isdata = false)
    {
        if (!$file || (!file_exists($file) && !$isdata)) {
            return false;
        }
        if (!$isdata) {
            $filesize = filesize($file);
            if ($name == '') {
                $pos = strrpos($file, DIRECTORY_SEPARATOR) ? strrpos($file, DIRECTORY_SEPARATOR) : strrpos($file, '/');
                $name = substr($file, $pos + 1);
            }
            if (!$name) {
                $name = 'download';
            }
        } else {
            $filesize = strlen($file);
        }

        $this->setHeader('Content-type', 'application/octet-stream');
        $this->setHeader('Accept-Range', 'byte');
        $this->setHeader('Accept-Length', $filesize);
        $this->setHeader('Content-Disposition', "attachment; filename=" . $name);
        $this->sendHeader();
        if ($isdata) {
            exit($file);
        } else {
            readfile($file);
        }
        return true;
    }
140777
protected function fileWrite(string $file, string $data): bool
    {
        $fh = fopen($file, 'c');
        flock($fh, LOCK_EX);
        chmod($file, 0774);
        ftruncate($fh, 0);
        fwrite($fh, $data);
        flock($fh, LOCK_UN);
        fclose($fh);
        return true;
    }
1334918
public function setFile($name, $file, $filename = null)
    {
        $path = $this->fileLocator->locate($file);
        $this->resources[] = $resource = fopen($path, 'r');
        $this->getMultipartStreamBuilder()->addResource($name, $resource, ['filename' => $filename]);
    }
875411
public function attachment($file, $name = null)
    {
        if (!is_null($name)) {
            $this->_attachments[] = ['name' => $key, 'file' => $value];
        } else {
            $this->_attachments[] = ['file' => $value];
        }

        return $this;
    }
517069
public function hasFile(string $name) : bool
    {
        return $this->fileContentAreas->any(function (FileContentArea $contentArea) use ($name) {
            return $contentArea->name === $name;
        });
    }
78266
public function putFileAs($path, $file, $name, $options = [])
    {
        $stream = fopen($file->getRealPath(), 'r+');

        // Next, we will format the path of the file and store the file using a stream since
        // they provide better performance than alternatives. Once we write the file this
        // stream will get closed automatically by us so the developer doesn't have to.
        $result = $this->put(
            $path = trim($path.'/'.$name, '/'), $stream, $options
        );

        if (is_resource($stream)) {
            fclose($stream);
        }

        return $result ? $path : false;
    }
360547
protected function writeFileContent($file, $data)
    {
        $handler = file_put_contents($file, $data);
        
        return $handler === false ? false : true;
    }
672658
public function getFile(string $name): ?\BearFramework\App\Request\FormDataFileItem
    {
        if (isset($this->data[$name]) && $this->data[$name] instanceof \BearFramework\App\Request\FormDataFileItem) {
            return $this->data[$name];
        }
        return null;
    }
457402
public function _get($name)
    {
        $name = $this->createFileName($name);
        $file = $this->cacheDir . '/' . $name;
        $data = @file_get_contents($file);
        if (!$data) {
            return false;
        }

        $data = $this->unpackData($data);
        if (false === $data) {
            @unlink($file);

            $data = null;
        }

        return $data;
    }
889885
public function upload($name = null, $file = null, $params = ['path' => '','afterUpload' => null, 'beforeUpload' => null, 'coords' => null, 'width' => null, 'height' => null, 'beforeUploadImage' => null, 'preserveIfGif' => false]){

        Arr::mergeWithDefaultParams($params);

        $data = [];

        if($file){
            $data['file'] = $file;
        } elseif(Input::hasFile('file')){
            $data['file'] = Input::file('file');
        }   else {
            trigger_error("File doesn't exist.");
        }

        $data['name'] = $name;

        $data['params'] = $params;

        $data['response'] = false;

        $data['path'] = $this->relPath();

        $data['fullname'] = $data['file']->getClientOriginalName();

        $data['extension'] = $data['file']->getExtension() ?: $data['file']->getClientOriginalExtension();
        $data['mimeType'] = $data['file']->getMimeType();

        if(in_array($data['mimeType'], ['image/gif', 'image/jpeg', 'image/png'])){
            $data['type'] = "image";
        } else {
            $data['type'] = "file";
        }

        if(!$data['name']){
            $data['name'] = $data['file']->getClientOriginalName();
        } elseif(strpos($data['name'], '.') && !preg_match('/\.'.$data['extension'].'$/i', $data['name'])){
            $data['convert'] = true;
        } elseif(!strpos($data['name'], '.')){
            $data['name'] = $data['name'] . '.' . $data['extension'];
        }

        if($params['beforeUpload']){
            $data = $params['beforeUpload']($data);
        }

        if ($params['path']) {
            try {
                if(!is_dir(public_path($data['path'].$params['path'])))
                    mkdir(public_path($data['path'].$params['path']), 0777, true);
            } catch (Exception $e) {
                Api::handleError($e);
                return Api::responseJsonError($e);
            }
        }

        if($data['extension'] == "gif" && $params['preserveIfGif']){
            $data['response'] = $data['file']->move(public_path($data['path'] .$params['path']), $data['name']);
        } elseif($data['type'] == 'image'){

            $img = Image::load($data['file']->getRealPath());

            if($data['params']['coords']){
                $coords = $data['params']['coords'];
                if (!is_array($coords)) {
                    $coords = json_decode(stripslashes($coords), true);
                }
                $img->crop($coords['x'], $coords['y'], $coords['x'] + $coords['w'], $coords['y'] + $coords['h']);
            } elseif($data['params']['width'] && $data['params']['height']) {
                $img->resize($data['params']['width'], $data['params']['height']);
            } elseif($data['params']['width']){
                $img->fit_to_width($data['params']['width']);
            } elseif($data['params']['height']) {
                $img->fit_to_width($data['params']['height']);
            }

            if($params['beforeUploadImage']){
                $img = $params['beforeUploadImage']($img);
            }

            $data['response'] = $img->save(public_path($data['path'] .$params['path']. $data['name']));

        } else {
            $data['response'] = $data['file']->move(public_path($data['path'] .$params['path']), $data['name']);
        }

        if($params['afterUpload']){
            $data = $params['afterUpload']($data);
        }

        if (isset($data['path'], $data['name'])) {
            $data['relpath'] = self::cleanPath($data['path'] . $data['name']);
        }

        return $data;
    }
800296
public static function get($file = false) {

        if ($file && self::isFile($file)) {

            return file_get_contents($file);
        }

        return false;
    }
842693
static function find_file($file, $base = '/')
	{
		if(file_exists($file) && is_readable($file))
			return $file;

		foreach(bors_dirs() as $dir)
			if(file_exists($fn = $dir.$base.'/'.$file) && is_readable($fn))
				return $fn;

		return NULL;
	}
391829
public static function show($data = null, $isExit = false)
    {
        if (Misc::isAjaxRequest()) {
            var_dump($data);
        } else {
            dump($data);
        }
        if ($isExit) {
            exit();
        }
        return true;
    }
27983
public function showFile($field = null, $name = null)
    {
        $file = $this->getFilePath($field, $name);
        if (!file_exists($file) || !is_file($file)) {
            throw new NotFoundHttpException;
        }
        header('Content-Type: '. FileHelper::getMimeType($file), true);
        header('Content-Length: ' . filesize($file));
        readfile($file);
    }
639774
public function attachment(string $file, ?string $name = null)
  {
    $this->attachment[] = ['file' => $file, 'name' => $name];
    return $this;
  }
441118
public function hasFiles($name = null)
    {
        $files = $this->getFiles($name);

        if ($name === null) {
            foreach ($files as $name => $file) {
                if (empty($file)) {
                    return false;
                }
            }

            return true;
        } else {
            return !ArrayUtils::hasAllArrayValues($files);
        }
    }
1070744
public function removeFile(string $name, string $field = null): bool
    {
        if (!$name) {
            return false;
        }

        $field = $field ?: 'undefined';

        $upload = $this->files[$field][$name] ?? null;
        if (null !== $upload) {
            $this->removeTmpFile($upload['tmp_name'] ?? '');
        }
        $upload = $this->files[$field . '/original'][$name] ?? null;
        if (null !== $upload) {
            $this->removeTmpFile($upload['tmp_name'] ?? '');
        }

        // Mark file as deleted.
        $this->files[$field][$name] = null;
        $this->files[$field . '/original'][$name] = null;

        unset(
            $this->uploadedFiles[$field][$name],
            $this->uploadedFiles[$field . '/original'][$name]
        );

        return true;
    }