Upload a file.

@param File  $file
@param mixed $raw_file

@return \Railken\Lem\Contracts\ResultContract
972496
public function uploadFile(File $file, $raw_file)
    {
        $result = new Result();

        if (file_exists($raw_file)) {
            return $this->uploadFileFromFilesystem($file, $raw_file);
        }

        return $result;
    }
6339
public function uploadFileByContent(File $file, string $content)
    {
        $dir = sys_get_temp_dir();

        $tmp = $dir.'/'.Uuid::uuid4()->toString();

        file_put_contents($tmp, $content);

        $filename = $file->name;

        if (!$filename) {
            $filename = Uuid::uuid4()->toString().'.'.$this->guessExtension($tmp);
        }

        $filename = $dir.'/'.$filename;

        rename($tmp, $filename);

        return $this->uploadFileFromFilesystem($file, $filename);
    }
1155737
public function uploadCoverAutoCrop($file)
    {
        $cover = $this->getTempCover();
        $uploadError = Nip_File_System::instance()->getUploadError($file, $cover->extensions);

        if (!$uploadError) {
            $cover->setResourceFromUpload($file);
            if ($cover->validate()) {
                /** @var \Organization_Cover_Default $defaultCover */
                $defaultCover = $this->getNewCover('default');
                $defaultCover->copyResource($cover);
                $defaultCover->cropToCenter($defaultCover->cropWidth, $defaultCover->cropHeight);
                $defaultCover->save();
                return $defaultCover;
            } else {
                $this->errors['upload'] = 'Eroare dimensiuni.';
            }
        } else {
            $this->errors['upload'] = $uploadError;
        }
    }
1147063
def upload(file)
      $stderr.puts "Uploading #{file}" if @verbose
      dir = File.dirname(file)
      makedirs(dir)
      @ftp.putbinaryfile(file, file) unless File.directory?(file)
    end
1362478
public function upload()
    {
        //as upload may be called multiple times, we remove the session lock as soon as possible
        try{
            session_write_close();
            if ($this->hasRequestParameter('uri')) {
                $itemUri = $this->getRequestParameter('uri');
                $item = $this->getResource($itemUri);
            }

            if ($this->hasRequestParameter('lang')) {
                $itemLang = $this->getRequestParameter('lang');
            }

            if (!$this->hasRequestParameter('path')) {
                throw new common_exception_MissingParameter('path', __METHOD__);
            }

            if (!$this->hasRequestParameter('filters')) {
                throw new common_exception_MissingParameter('filters', __METHOD__);
            }
            $filters = $this->getRequestParameter('filters');

            $resolver = new ItemMediaResolver($item, $itemLang);
            $asset = $resolver->resolve($this->getRequestParameter('relPath'));

            $file = tao_helpers_Http::getUploadedFile('content');
            $fileTmpName = $file['tmp_name'].'_'.$file['name'];

            if (!tao_helpers_File::copy($file['tmp_name'], $fileTmpName)) {
                throw new common_exception_Error('impossible to copy '.$file['tmp_name'].' to '.$fileTmpName);
            }

            $mime = \tao_helpers_File::getMimeType($fileTmpName);
            if (is_string($filters)) {
                // the mime type is part of the $filters
                $filters = explode(',', $filters);
                if ((in_array($mime, $filters))) {
                    $filedata = $asset->getMediaSource()->add($fileTmpName, $file['name'],
                        $asset->getMediaIdentifier());
                } else {
                    throw new FileUploadException(__('The file you tried to upload is not valid'));
                }
            } else {
                $valid = false;
                // OR the extension is part of the filter and it correspond to the mime type
                foreach ($filters as $filter) {
                    if ($filter['mime'] === $mime &&
                        (!isset($filter['extension']) || $filter['extension'] === \tao_helpers_File::getFileExtention($fileTmpName))
                    ) {
                        $valid = true;
                    }
                }
                if ($valid) {
                    $filedata = $asset->getMediaSource()->add($fileTmpName, $file['name'],
                        $asset->getMediaIdentifier());
                } else {
                    throw new FileUploadException(__('The file you tried to upload is not valid'));
                }
            }

            $this->returnJson($filedata);
            return;
        }
        catch(PermissionException $e){
            $message = $e->getMessage();
        }
        catch(FileUploadException $e){
            $message = $e->getMessage();
        }
        catch(common_Exception $e){
            $this->logWarning($e->getMessage());
            $message = _('Unable to upload file');
        }
        $this->returnJson(array('error' => $message));

    }
499953
public function file(UploadedFile $file)
	{
		$this->file = $file;
		$this->filename = $file->getClientOriginalName();
		$this->sanitizeFilename();

		return $this;
	}
124798
public function upload($file, $key)
    {
        if (! $file || ! $this->isValidKey($key))
            return;

        $fileName = $file->getClientOriginalName();
        $pathinfo = pathinfo($fileName);

        $this->deleteStored($key);

        Storage::putFileAs($this->getStoragePath(), $file, $key . '.' . $pathinfo['extension']);
    }
11125
protected function uploadFileToCloudinary($file, $publicId)
    {
        $result = $this->uploader->upload(
            $file->getRealPath(),
            [
                'public_id' => $publicId,
            ]
        );

        return $result;
    }
623027
public function put($local_file = null, $remote_file = null, $mode = FTP_ASCII)
    {
        if (\ftp_put($this->_stream, $remote_file, $local_file, $mode)) {
            return true;
        }

        $this->error = 'Failed to upload file "'.$local_file.'"';

        return false;
    }
39534
public static function createFromFile(PHPRtfLite $rtf, $file, $width = null, $height = null)
    {
        if (is_readable($file)) {
            $stream = fopen($file, 'rb');
            $pathInfo = pathinfo($file);
            $type = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : 'jpeg';
            $image = self::create($rtf, $stream, $type, $width, $height);

            if ($type != self::TYPE_WMF) {
                list($width, $height, $imageType) = getimagesize($file);
                $imageType = image_type_to_extension($imageType, false);
                $image->setImageWidth($width);
                $image->setImageHeight($height);
                if ($type != $imageType) {
                    $image->setImageType($imageType);
                }
            }
            return $image;
        }

        return self::createMissingImage($rtf, $width, $height);
    }
943368
def save(file)
      File.open(file, "w") do |f|
        f.write(@raw_cert.to_pem)
      end
      true
    end
521085
private function log(string $file, $msg, bool $raw = false)
    {
        // 全局日志开关
        $enable = configDefault(false, 'log', 'enable');
        if (!$enable and !$this->isConfigDebug) {
            return false;
        }

        // 数据格式转为字符串
        $msg = $this->msg($msg);

        // 写入一个空行
        if (!$msg) {
            return $this->write($file, PHP_EOL);
        }

        // 是否要求不附加日期数据
        return $this->write($file, $raw ? $msg : date('H:i:s') . "\t" . $msg . PHP_EOL);
    }
254160
def upload_file(self, remote, local):
        
        file = open(local, 'rb')
        try:
            self.upload(remote, file)
        finally:
            file.close()
56030
public function add($file, $entry_name = null)
    {
        // Make sure to adapt the entry name as the original filename.
        if (isset($entry_name)) {
            $this->phar->addFile($file, $entry_name);
        }
        else {
            $this->phar->addFile($file);
        }

        return $this;
    }
8647
public function upload(FileRequest $request)
    {
        $crudeName = $request->input('crudeName');
        $crude = CrudeInstance::get($crudeName);
        $files = $request->file()['file'];
        $id = $request->input('modelId');
        $errors = [];

        if ($crude instanceof \JanDolata\CrudeCRUD\Engine\Interfaces\WithValidationInterface) {
            foreach($files as $key => $file) {
                $rules = $crude->getValidationRules(['file']);

                $mime = $file->getMimeType();
                $fileTypeRules = 'file_'.collect(explode('/', $mime))->first();

                empty($crude->getValidationRules([$fileTypeRules])[$fileTypeRules])
                    ? $rules = $rules
                    : $rules['file'] = $rules['file'] . '|' . $crude->getValidationRules([$fileTypeRules])[$fileTypeRules];

                $validator = Validator::make(['file' => $file], $rules);

                if ($validator->fails()) {
                    unset($files[$key]);
                    $errors[] = $file->getClientOriginalName() . ': '. $validator->messages()->first();
                }
            }
        }

        $model = empty($files)
            ? $crude->getById($id)
            : $crude->uploadFilesById($id, $files);

        $response = ['success' => true, 'model' => $model];

        if (!empty($errors)) {
            $response = array_merge($response, ['errors' => join('<br/>', $errors)]);
            $response['success'] = false;
        }

        return $response;
    }
1189466
public function joinRaw($table, $column1, $operator, $raw, string $type = 'INNER')
	{
		return $this->join($table, $column1, $operator, $raw, $type, true);
	}
757425
public GitlabUpload uploadFile(GitlabProject project, File file) throws IOException {
        String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(project.getId()) + GitlabUpload.URL;
        return dispatch().withAttachment("file", file).to(tailUrl, GitlabUpload.class);
    }