Flow Uploader Upload.

@return string
351986
public function callbackUpload()
    {
        $config = new Config();
        $config->setTempDir($this->getTempFolder());
        $file = new File($config);
        $request = new Request();
        
        if ($_SERVER['REQUEST_METHOD'] === 'GET') {
            if ($file->checkChunk()) {
                header("HTTP/1.1 200 Ok");
            } else {
                header("HTTP/1.1 204 No Content");
                exit;
            }
        } else {
            if ($file->validateChunk()) {
                $file->saveChunk();
            } else {
                // error, invalid chunk upload request, retry
                header("HTTP/1.1 400 Bad Request");
                exit;
            }
        }
        if ($file->validateFile() && $file->save($this->getUploadFolder() . '/'.$request->getFileName())) {
            // File upload was completed
            $file = Yii::$app->storage->addFile($this->getUploadFolder() . '/'.$request->getFileName(), $request->getFileName(), 0, true);
            
            if ($file) {
                @unlink($this->getUploadFolder() . '/'.$request->getFileName());
                
                $image = Yii::$app->storage->addImage($file->id);
                if ($image) {
                    $image->applyFilter('small-crop');
                    
                    $this->model->flowSaveImage($image);
                    return 'done';
                }
            }
        } else {
            // This is not a final chunk, continue to upload
        }
    }
1291442
public function getFlowMax()
    {
        $resultGraph = $this->createGraph();

        $start = $resultGraph->getVertex($this->startVertex->getId());
        $maxFlow = 0;
        foreach ($start->getEdgesOut() as $edge) {
            $maxFlow = $maxFlow + $edge->getFlow();
        }

        return $maxFlow;
    }
1158164
public function upload()
        {
            $files = $this->getFiles();
            $response = [];
            $types = new ImageUploadTypes();
            foreach($files as $file){

                if(!$file instanceof ImageUpload)
                {
                    $file = new ImageUpload($file);
                    $file->setAllowedMimeTypes($types->getImageMimeTypes());
                    $file->setAllowedExt($types->getImageTypeExt(), ['.php']);
                }

                $response[] = $file->upload();
            }

            return $response;
        }
1037377
public function getFilePath() {

		if( isset( $this->url ) ) {

			return Yii::$app->fileManager->uploadDir . '/' . $this->url;
		}

		return false;
	}
34124
public function upload()
    {
        $position = $this->request->getQuery('position');
        $positions = $this->viewVars['positions']->toArray();

        //If there's only one available position
        if (!$position && count($positions) < 2) {
            $position = array_key_first($positions);
            $this->request = $this->request->withQueryParams(compact('position'));
        }

        if ($this->request->getData('file')) {
            is_true_or_fail($position, __d('me_cms', 'Missing ID'), InternalErrorException::class);

            $uploaded = $this->Uploader->set($this->request->getData('file'))
                ->mimetype('image')
                ->save(BANNERS);

            if (!$uploaded) {
                return $this->setUploadError($this->Uploader->getError());
            }

            $entity = $this->Banners->newEntity([
                'position_id' => $position,
                'filename' => basename($uploaded),
            ]);

            if ($entity->getErrors()) {
                return $this->setUploadError(array_value_first_recursive($entity->getErrors()));
            }

            if (!$this->Banners->save($entity)) {
                $this->setUploadError(I18N_OPERATION_NOT_OK);
            }
        }
    }
1355900
public function getFileUrl() {

		if( $this->changed ) {

			return Yii::$app->fileManager->uploadUrl . '/' . CoreProperties::DIR_TEMP . $this->directory . "/" . $this->name . "." . $this->extension;
		}
		else if( $this->id > 0 ) {

			return Yii::$app->fileManager->uploadUrl . '/' . $this->url;
		}

		return "";
	}
954286
public function actionUpload()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;

        $model = new Mediafile();
        $routes = $this->module->routes;
        $rename = $this->module->rename;
	    $tagIds = Yii::$app->request->post('tagIds');

	    if ($tagIds !== 'undefined') {
		    $model->setTagIds(explode(',', $tagIds));
	    }

        $model->saveUploadedFile($routes, $rename);
        $bundle = FilemanagerAsset::register($this->view);

        if ($model->isImage()) {
            $model->createThumbs($routes, $this->module->thumbs);
        }

        $response['files'][] = [
            'url'           => $model->url,
            'thumbnailUrl'  => $model->getDefaultThumbUrl($bundle->baseUrl),
            'name'          => $model->filename,
            'type'          => $model->type,
            'size'          => $model->file->size,
            'deleteUrl'     => Url::to(['file/delete', 'id' => $model->id]),
            'deleteType'    => 'POST',
        ];

        return $response;
    }
261108
public function getStats()
    {
        $this->resetTotals();
        foreach ($this->flow->getNodes() as $node) {
            $nodeMap = $this->nodeMap[$node->getId()];
            foreach ($this->incrementTotals as $srcKey => $totalKey) {
                if (isset($nodeMap[$srcKey])) {
                    $this->flowStats[$totalKey] += $nodeMap[$srcKey];
                }
            }

            if ($node instanceof BranchNodeInterface) {
                $childFlowId                               = $node->getPayload()->getId();
                $this->flowStats['branches'][$childFlowId] = $node->getPayload()->getStats();
                foreach ($this->incrementTotals as $srcKey => $totalKey) {
                    if (isset($this->flowStats['branches'][$childFlowId][$totalKey])) {
                        $this->flowStats[$totalKey] += $this->flowStats['branches'][$childFlowId][$totalKey];
                    }
                }
            }
        }

        $flowStatus = $this->flow->getFlowStatus();
        if ($flowStatus !== null) {
            $this->flowStats['flow_status'] = $flowStatus->getStatus();
        }

        return $this->flowStats;
    }
289593
private function upload_image()
    {

        /* validate the image */
        $validation    = Validator::make($this->image, array($this->input => $this->rules));
        $errors        = array();
        $original_name = $this->image[$this->input]->getClientOriginalName();
        $path          = '';
        $filename      = '';
        $resizes       = '';

        if ($validation->fails()) {
            /* use the messages object for the erros */
            $errors = implode('. ', $validation->messages()->all());
        } else {
            if ($this->random) {
                if (is_callable($this->random_cb)) {
                    $filename = call_user_func($this->random_cb, $original_name);
                } else {
                    $ext      = File::extension($original_name);
                    $filename = $this->generate_random_filename().'.'.$ext;
                }
            } else {
                $filename = $original_name;
            }

            /* upload the file */
            $save = $this->image[$this->input]->move($this->path, $filename);
            //$save = Input::upload($this->input, $this->path, $filename);

            if ($save) {
                $path = $this->path.$filename;

                if (is_array($this->image_sizes)) {
                    $resizer = new Resize();
                    $resizes = $resizer->create($save, $this->path, $filename, $this->image_sizes);
                }
            } else {
                $errors = 'Could not save image';
            }
        }

        return compact('errors', 'path', 'filename', 'original_name', 'resizes');
    }
1356589
protected function uploadSingleFile()
    {
        // check if there is error while uploading from error array key.
        if (is_array($this->files[$this->input_file_name]) && array_key_exists('error', $this->files[$this->input_file_name]) && $this->files[$this->input_file_name]['error'] != 0) {
            switch ($this->files[$this->input_file_name]['error']) {
                case 1:
                    $this->setErrorMessage(
                        sprintf(static::__('The uploaded file exceeds the max file size directive. (%s &gt; %s).'), $this->files[$this->input_file_name]['size'], ini_get('upload_max_filesize')),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        $this->files[$this->input_file_name]['size'] . ' &gt; ' . ini_get('upload_max_filesize'),
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 2:
                    $this->setErrorMessage(
                        static::__('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 3:
                    $this->setErrorMessage(
                        static::__('The uploaded file was only partially uploaded.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 4:
                    $this->setErrorMessage(
                        static::__('You did not upload the file.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 6:
                    $this->setErrorMessage(
                        static::__('Missing a temporary folder.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 7:
                    $this->setErrorMessage(
                        static::__('Failed to write file to disk.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
                case 8:
                    $this->setErrorMessage(
                        static::__('A PHP extension stopped the file upload.'),
                        'RDU_' . $this->files[$this->input_file_name]['error'],
                        '',
                        $this->files[$this->input_file_name]['name'],
                        $this->files[$this->input_file_name]['size'],
                        $this->files[$this->input_file_name]['type']
                    );
                    return false;
            }
        }

        // validate that there is file upload.
        if (
            empty($this->files[$this->input_file_name]) || 
            (
                is_array($this->files[$this->input_file_name]) && 
                array_key_exists('name', $this->files[$this->input_file_name]) && 
                $this->files[$this->input_file_name]['name'] == null
            ) ||
            (
                is_array($this->files[$this->input_file_name]) && 
                array_key_exists('tmp_name', $this->files[$this->input_file_name]) && 
                $this->files[$this->input_file_name]['tmp_name'] == null
            )
        ) {
            $this->setErrorMessage(
                static::__('You did not upload the file.'),
                'RDU_4',
                '',
                $this->files[$this->input_file_name]['name'],
                $this->files[$this->input_file_name]['size'],
                $this->files[$this->input_file_name]['type']
            );
            return false;
        }

        // validate allowed extension and its mime types.
        $result = $this->validateExtensionAndMimeType();
        if ($result !== true) {
            return false;
        }
        unset($result);

        // validate max file size.
        $result = $this->validateFileSize();
        if ($result !== true) {
            return false;
        }
        unset($result);

        // validate max image dimension.
        $result = $this->validateImageDimension();
        if ($result !== true) {
            return false;
        }
        unset($result);

        // security scan.
        if ($this->security_scan === true) {
            $result = $this->securityScan();
            if ($result !== true) {
                return false;
            }
            unset($result);
        }

        // set new file name (in case that it was not set) and check for reserved file name.
        $tmp_new_file_name = $this->new_file_name;
        $this->setNewFileName();

        // check for safe web file name if this option was set to true.
        if ($this->web_safe_file_name === true) {
            $this->setWebSafeFileName();
        }

        // now, it should all passed validation. add the uploaded file to move uploaded queue in case that it is upload multiple file and has option to stop on error.
        // get the uploaded file extension.
        $file_name_explode = explode('.', $this->files[$this->input_file_name]['name']);
        $file_extension = null;
        if (is_array($file_name_explode)) {
            $file_extension = '.'.$file_name_explode[count($file_name_explode)-1];
        }
        unset($file_name_explode);
        // add to queue.
        $this->move_uploaded_queue = array_merge(
            $this->move_uploaded_queue, 
            array(
                $this->files[$this->input_file_name]['input_file_key'] => array(
                    'name' => $this->files[$this->input_file_name]['name'],
                    'tmp_name' => $this->files[$this->input_file_name]['tmp_name'],
                    'new_name' => $this->new_file_name.$file_extension,
                )
            )
        );
        // restore temp of new file name to ready for next loop of upload multiple.
        $this->new_file_name = $tmp_new_file_name;
        unset($file_extension, $tmp_new_file_name);

        // done.
        return true;
    }
724957
protected function createFlowrouteDriver()
    {
        $config = $this->app['config']->get('sms.flowroute', []);

        $provider = new FlowrouteSMS(
            new Client(),
            $config['access_key'],
            $config['secret_key']
        );

        return $provider;
    }
692020
public function getCurrentUploadDir()
    {
        if (! isset($this->currentUploadDir)) {
            $modelDir = $this->getIdentifier();
            $this->currentUploadDir = public_path($this->uploadDir).DIRECTORY_SEPARATOR.$modelDir.
                DIRECTORY_SEPARATOR.$this->getKey().DIRECTORY_SEPARATOR;
        }

        return $this->currentUploadDir;
    }
1172170
public function uploadCover()
    {
        $cover = $this->getTempCover();
        $file = $_FILES['Filedata'];
        $uploadError = Nip_File_System::instance()->getUploadError($file, $cover->extensions);

        if (!$uploadError) {
            $cover->setResourceFromUpload($file);
            if ($cover->validate()) {
                $cover->resize();
                $cover->save();

                $coverCrop = $this->getTempCover();
                $coverCrop->copyResource($cover);

                $max_width = 600;
                $reductionRatio = 600 / $coverCrop->getWidth();

                $coverCrop->max_width = $max_width;
                $coverCrop->setName('crop-' . $cover->name);
                $coverCrop->resize();
                $coverCrop->save();

                $defaultCover = $this->getNewCover('default');
                $coverCrop->cropWidth = $defaultCover->cropWidth * $reductionRatio;
                $coverCrop->cropHeight = $defaultCover->cropHeight * $reductionRatio;

                return $coverCrop;
            } else {
                $this->errors['upload'] = 'Eroare dimensiuni.';
            }
        } else {
            $this->errors['upload'] = $uploadError;
        }


        return false;
    }
1114785
public function uploadFile()
	{
        if (!isset(Yii::app()->params['ciims_plugins']['upload']))
        {
            Yii::import('cii.utilities.CiiFileUploader');
            $className = 'CiiFileUploader';
        }
        else
            $className = Yii::app()->params['ciims_plugins']['upload']['class'];

        $config = isset(Yii::app()->params['ciims_plugins']['upload']['options']) ? Yii::app()->params['ciims_plugins']['upload']['options'] : array();
        $class = new $className($config);
        $this->_result = $class->upload();
        $this->_response = $this->_handleResourceUpload($this->_result['url']);

        return $this->_response;
	}
532505
public function getMaxUploadSize()
    {
        $maxUpload = (int)(ini_get('upload_max_filesize'));
        $maxPost = (int)(ini_get('post_max_size'));
        $memoryLimit = (int)(ini_get('memory_limit'));
        return min($maxUpload, $maxPost, $memoryLimit);
    }
397841
public function getStream(){
        if(UPLOAD_ERR_OK !== $this->error){
            throw new Exception\UploadErrorException(
                static::ERROR_MAP[$this->error]
            );
        }

        if($this->moved){
            throw new Exception\UploadFileIsMovedException(
                "The uploaded file has already been moved."
            );
        }

        return $this->stream;
    }
837340
public function upload()
    {
        $params = $this->getUploadParams();

        if ($params) {
            $class = $this->class;
            $uri = $class::getUri();
            $document = static::post($this->client, $uri, $params);

            /** @var Model $instance */
            $instance = new $this->class($this->client, $document);
            $instance->exists = true;
            $instance->cacheFields($document);
            return $instance;
        }

        return null;
    }