Return a base64 encoded representation of the upload.

@since 1.0.0

@return string
431023
public function to_base64()
    {
        if (!empty($this->get_upload_path())) {
            return \base64_encode(\file_get_contents($this->get_upload_path()));
        }

        return \base64_encode(\file_get_contents($this->get_tmp_path()));
    }
1315491
public function getEncoding()
    {
        if ($this->options['encoding'] === null && function_exists('mb_internal_encoding')) {
            $this->options['encoding'] = mb_internal_encoding();
        }

        return $this->options['encoding'];
    }
360126
public function generateSigninInput()
    {
        $base64payload = $this->encoder->encode(json_encode($this->getPayload(), JSON_UNESCAPED_SLASHES));
        $base64header = $this->encoder->encode(json_encode($this->getHeader(), JSON_UNESCAPED_SLASHES));

        return sprintf('%s.%s', $base64header, $base64payload);
    }
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;
    }
1161745
protected function getClientChecksum()
    {
        $checksumHeader = $this->getRequest()->header('Upload-Checksum');

        if (empty($checksumHeader)) {
            return '';
        }

        list($checksumAlgorithm, $checksum) = explode(' ', $checksumHeader);

        $checksum = base64_decode($checksum);

        if ( ! in_array($checksumAlgorithm, hash_algos()) || false === $checksum) {
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
        }

        return $checksum;
    }
1245702
public function convert() {

        $resource = $file = \tao_helpers_Http::getUploadedFile('content');

        $base64Converter = new Base64ConverterModel($resource);

        $this -> returnJson($base64Converter->convertToBase64());
    }
1288082
public function getBase64()
    {
        if ($this->owner->exists()) {
            $file = $this->owner->getFullPath();
            $mime = mime_content_type($file);
            $fileContent = file_get_contents($file);
            return "data://$mime;base64," . base64_encode($fileContent);
        }
        
        return null;
    }
350790
protected function encode(): string
    {
        $bitmap = null;
        $lastRow = null;

        for ($y = 0; $y < $this->height; $y++) {
            $bits = null;

            for ($x = 0; $x < $this->width; $x++) {
                $bits .= $this->decoder->getBitAt($x, $y);
            }

            $bytes = str_split($bits, 8);
            $bytes[] = str_pad(array_pop($bytes), 8, '0');

            $row = null;

            foreach ($bytes as $byte) {
                $row .= sprintf('%02X', bindec($byte));
            }

            $bitmap .= $this->compress($row, $lastRow);
            $lastRow = $row;
        }

        return $bitmap;
    }
382262
public function uploadImage()
    {
        $image = $this->getTempImage();
        $file = $_FILES['Filedata'];
        $uploadError = Nip_File_System::instance()->getUploadError($file, $image->extensions);

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

                $imageCrop = $this->getTempImage();
                $imageCrop->copyResource($image);

                $ratio = $imageCrop->getRatio();
                $max_width = $imageCrop->minWidth > 600 ? $imageCrop->minWidth : 600;
                $heightCalculated = round($max_width / $ratio);
                if ($heightCalculated < $imageCrop->minHeight) {
                    $max_width = round($imageCrop->minHeight * $ratio);
                }

                $imageCrop->max_width = $max_width;
                $imageCrop->setName('crop-' . $image->name);
                $imageCrop->resize();
                $imageCrop->save();

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


        return false;
    }
1231215
public function getKey(): string
    {
        if (starts_with($this->key, 'base64:')) {
            return base64_decode(mb_substr($this->key, 7));
        }

        return $this->key;
    }
1371100
protected function makeBase64Image($_base64_data) {

		$_img = base64_decode($_base64_data);
        $this->fileInfo['local_name'] = time().".png";
		$_filename = $this->getFileName($this->fileInfo['local_name']);
        $this->fileInfo['file_name'] = $_filename;
        $this->fileInfo['file_path'] = $this->config['upload_dir'].DIRECTORY_SEPARATOR.$_filename;
		if ( file_put_contents($this->fileInfo['file_path'], $_img) && file_exists($this->fileInfo['file_path']) ) {

            $size = getimagesize($this->fileInfo['file_path']);
            if ( ($this->config['max_width'] > 0 && $size[0] > $this->config['max_width'])
                || ($this->config['max_height'] > 0 && $size[1] > $this->config['max_height']) )  {

                $this->errNum = 9;
                return false;

            }
            $this->fileInfo['image_width'] = $size[0];
            $this->fileInfo['image_height'] = $size[1];
            //初始化mimeType
            $this->fileInfo['file_type'] = "image/png";
            $this->fileInfo['is_image'] = 1;
            $this->fileInfo['file_size'] = filesize($this->fileInfo['file_path']);

            $pathinfo = pathinfo($this->fileInfo['file_path']);
            $this->fileInfo['file_ext'] =  $pathinfo['extension'];
            $this->fileInfo['raw_name'] = $pathinfo['filename'];

            return $this->fileInfo;
		}
		$this->errNum = 8;

        return false;
	}
37797
protected function _getContentTransferEncoding()
    {
        if ($this->transferEncoding) {
            return $this->transferEncoding;
        }

        $charset = strtoupper($this->charset);
        if (in_array($charset, $this->_charset8bit)) {
            return '8bit';
        }

        return '7bit';
    }
784329
protected function uploadArchive()
    {

        if ($_FILES['content']['error'] !== UPLOAD_ERR_OK) {

            \common_Logger::w('File upload failed with error ' . $_FILES['content']['error']);
            switch ($_FILES['content']['error']) {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $error = __('Archive size must be lesser than : ') . ini_get('post_max_size');
                    break;
                case UPLOAD_ERR_NO_FILE:
                    $error = __('No file uploaded');
                    break;
                default:
                    $error = __('File upload failed');
                    break;
            }
            return array('error' => $error);
        }

        $filePath = $this->tmpDir . '/' . $_FILES['content']['name'];
        if (!move_uploaded_file($_FILES['content']['tmp_name'], $filePath)) {
            return array('error' => __('Unable to move uploaded file'));
        }

        return $filePath;
    }
119143
public function toBytes(): string
    {
        $bytes = '';
        $hex = $this->toHex();

        foreach (range(0, 30, 2) as $i) {
            $bytes .= chr(hexdec(substr($hex, $i, 2)));
        }

        return $bytes;
    }
1242583
public static function maxBytesUpload ()
		{
			$values = [
				ini_get('post_max_size'),
				ini_get('upload_max_filesize'),
				ini_get('memory_limit'),
			];

			$min = false;
			foreach ($values as $v)
			{
				if ($v != -1)
				{
					$bytes = self::toBytes($v);
					if ($bytes != null)
						$min = $min ? min($min, $bytes) : $bytes;
				}
			}

			return $min ? $min : null;
		}
405264
public function generateHash(): string
    {
        $h = sprintf('%s%s%s', (string)$this->getIdentificator(), $this->getExpiration(), $this->getSecret());
        $h = md5($h, true);
        $h = self::base64url_encode($h);
        return $h;
    }
200758
public function encode()
    {
        return $this->header->encode() . $this->getContent() . \str_repeat("\0", $this->header->getPaddingLength());
    }