Download an image file from Livedocx

@return string

@throws DownloadException
772715
public function download()
    {
        try {
            $result = $this->getSoapClient()->DownloadImage(array(
                'filename' => basename($this->filename) ,
            ));

            return base64_decode($result->DownloadImageResult);
        } catch ( SoapException $e ) {
            throw new DownloadException('Error while downloading the image' , $e);
        }
    }
420794
public function getImageAttribute()
    {
        $defaultPath = '/img/default-product.jpg';
        $image = $this->images()->where('is_main_image', '=', 1)->first();

        if (null === $image) {
            return new LocalFile($defaultPath);
        }

        if ($image->path instanceof LocalFile) {
            return $image->path;
        }
    }
1133024
protected function getUploadedImage()
    {
        if ($this->getMappingResultsForProperty()->hasErrors()) {
            return null;
        }
        $image = $this->getPropertyValue();
        if ($image instanceof Image) {
            return $image;
        }
        return $this->propertyMapper->convert($this->getValueAttribute(), Image::class);
    }
40826
public function downloadAttachment($attachmentIndex)
    {
        $fileInformation = $this->GetAttachment($attachmentIndex);
        //build URI to download attachment
        $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() . '/attachments/' . $attachmentIndex . '/download';
        //sign URI
        $signedURI = Utils::sign($strURI);
        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
        $v_output = Utils::validateOutput($responseStream);
        if ($v_output === '') {
            Utils::saveFile($responseStream, AsposeApp::$outPutLocation . $fileInformation->Name);
            return '';
        } else
            return $v_output;
    }
780256
public function downloadFile($uri)
    {
        $fileUtil = new FileUtil();
        $file = tempnam($fileUtil->getTempDirectory(), "bavdownload");
        $fp   = fopen($file, 'w');
        if (! ($file && $fp)) {
            throw new DownloaderException("Failed opening a temporary file");

        }
        curl_setopt($this->handle, CURLOPT_FILE, $fp);

        if (! $this->download($uri)) {
            fclose($fp);
            unlink($file);
            throw new DownloaderException(curl_error($this->handle), curl_errno($this->handle));

        }
        return $file;
    }
110363
public function download()
    {
        $basedir = dirname($this->fileName);
        foreach ($this->data as $fetch) {
            $filename = $basedir . '/' . $fetch['filename'];
            if (! file_exists($filename)) {
                $this->_downloadFile($fetch['url'], $filename);
            }
        }
    }
336574
public function downloadAction()
    {
        $model = $this->getModel();
        $model->applyRequest($this->getRequest());

        $fileData = $model->loadFirst();

        header('Content-Type: application/x-download');
        header('Content-Length: '.$fileData['size']);
        header('Content-Disposition: inline; filename="'.$fileData['filename'].'"');
        header('Pragma: public');

        echo $fileData['content'];
        exit();
    }
798470
public function getWrappedImage()
    {
        if(!$this->zendImage)
        {
            $this->zendImage = $this->createImage($this->path);
            $this->path = null;
        }

        return $this->zendImage;
    }
663929
public function getImagineImage()
    {
        if (empty($this->imagineImage)) {
            $this->assertImagine();
            $binaryContent = $this->getBinaryContent();
            if (empty($binaryContent)) {
                throw new ImageException('Empty image', ImageException::EMPTY_IMAGE);
            }
            $this->imagineImage = $this->getImagine()->load($binaryContent);
        }
        return $this->imagineImage;
    }
853387
public function getLocalCopy()
    {
        /** @var ConfigModel $settings */
        $config = ImagerService::getConfig();

        if ($this->type !== 'local') {
            if (!file_exists($this->getFilePath()) || (($config->cacheDurationRemoteFiles !== false) && ((FileHelper::lastModifiedTime($this->getFilePath()) + $config->cacheDurationRemoteFiles) < time()))) {
                if ($this->asset && $this->type === 'volume') {
                    /** @var Volume $volume */
                    try {
                        $volume = $this->asset->getVolume();
                    } catch (InvalidConfigException $e) {
                        Craft::error($e->getMessage(), __METHOD__);
                        throw new ImagerException($e->getMessage(), $e->getCode(), $e);
                    }

                    $volume->saveFileLocally($this->asset->getPath(), $this->getFilePath());
                }

                if ($this->type === 'remoteurl') {
                    $this->downloadFile();
                }

                if (file_exists($this->getFilePath())) {
                    ImagerService::registerCachedRemoteFile($this->getFilePath());
                }
            }

            if (!file_exists($this->getFilePath())) {
                $msg = Craft::t('imager', 'File could not be downloaded and saved to “{path}”', ['path' => $this->path]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }
        }
    }
723095
private function download()
    {
        header('Content-disposition: attachment; filename="'.$this->filename.'.'.$this->extension.'"');
        header('Content-type: application/octet-stream');
        
        readfile($this->filename.'.'.$this->extension);
    }
547015
public function download()
    {
        try{
            $this->checkIfTaskIdExists();

            $taskLogEntity = $this->getTaskLogService()->getByIdAndUser(
                $this->getRequestParameter(self::PARAMETER_TASK_ID),
                $this->getSessionUserUri()
            );

            if (!$taskLogEntity->getStatus()->isCompleted()) {
                throw new \common_Exception('Task "'. $taskLogEntity->getId() .'" is not downloadable.');
            }

            $fileNameOrSerial = $taskLogEntity->getFileNameFromReport();

            if (empty($fileNameOrSerial)) {
                throw new \common_Exception('Filename not found in report.');
            }

            // first try to get a referenced file is it is a serial
            $file = $this->getReferencedFile($fileNameOrSerial);

            // if no file let's try the task queue storage
            if (is_null($file)) {
                $file = $this->getQueueStorageFile($fileNameOrSerial);
            }

            if (!$file) {
                throw new \common_exception_NotFound('File not found.');
            }

            header('Set-Cookie: fileDownload=true');
            setcookie('fileDownload', 'true', 0, '/');
            header('Content-Disposition: attachment; filename="' . $file->getBasename() . '"');
            header('Content-Type: ' . $file->getMimeType());

            \tao_helpers_Http::returnStream($file->readPsrStream());
            exit();
        } catch (\Exception $e) {
            return $this->returnJson([
                'success' => false,
                'errorMsg' => $e instanceof \common_exception_UserReadableException ? $e->getUserMessage() : $e->getMessage(),
                'errorCode' => $e->getCode(),
            ]);
        }
    }
632195
public function iconDownload()
    {
        if ($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) {
            return;
        }

        $download = $this->getParent()->transferInitDownload(
            rand(0x0000, 0xFFFF),
            0,
            $this->iconGetName("client_icon_id")
        );
        $transfer = Teamspeak::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);

        return $transfer->download($download["ftkey"], $download["size"]);
    }
1026551
public function avatarDownload()
    {
        if ($this["client_flag_avatar"] == 0) {
            return;
        }

        $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName());
        $transfer = Teamspeak::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);

        return $transfer->download($download["ftkey"], $download["size"]);
    }
993665
protected function getImageUrlOrDefault()
    {
        $file = '';

        if (is_object($this->entity->image)) {
            $file = $this->entity->image->path;
        }

        if (!Storage::exists($file)) {
            $file = $this->imgNotFound();
        }

        return Storage::url($file);
    }
1340505
private function downloadFile()
    {
        /** @var ConfigModel $settings */
        $config = ImagerService::getConfig();

        // url encode filename to account for non-ascii characters in filenames.
        $imageUrlArr = explode('?', $this->url);

        $imageUrlArr[0] = preg_replace_callback('#://([^/]+)/([^?]+)#', function($match) {
            return '://'.$match[1].'/'.implode('/', array_map('rawurlencode', explode('/', $match[2])));
        }, urldecode($imageUrlArr[0]));

        $imageUrl = implode('?', $imageUrlArr);

        if (\function_exists('curl_init')) {
            $ch = curl_init($imageUrl);
            $fp = fopen($this->getFilePath(), 'wb');
            
            $defaultOptions = [
                CURLOPT_FILE => $fp,
                CURLOPT_HEADER => 0,
                CURLOPT_FOLLOWLOCATION => 1,
                CURLOPT_TIMEOUT => 30
            ];

            // merge default options with config setting, config overrides default.
            $options = $config->getSetting('curlOptions') + $defaultOptions;

            curl_setopt_array($ch, $options);
            curl_exec($ch);
            $curlErrorNo = curl_errno($ch);
            $curlError = curl_error($ch);
            $httpStatus = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            fclose(/** @scrutinizer ignore-type */ $fp);

            if ($curlErrorNo !== 0) {
                unlink($this->getFilePath());
                $msg = Craft::t('imager', 'cURL error “{curlErrorNo}” encountered while attempting to download “{imageUrl}”. The error was: “{curlError}”', ['imageUrl' => $imageUrl, 'curlErrorNo' => $curlErrorNo, 'curlError' => $curlError]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }

            if ($httpStatus !== 200) {
                if (!($httpStatus === 404 && strrpos(mime_content_type($this->getFilePath()), 'image') !== false)) { // remote server returned a 404, but the contents was a valid image file
                    unlink($this->getFilePath());
                    $msg = Craft::t('imager', 'HTTP status “{httpStatus}” encountered while attempting to download “{imageUrl}”', ['imageUrl' => $imageUrl, 'httpStatus' => $httpStatus]);
                    Craft::error($msg, __METHOD__);
                    throw new ImagerException($msg);
                }
            }
        } elseif (ini_get('allow_url_fopen')) {
            if (!@copy($imageUrl, $this->getFilePath())) {
                unlink($this->getFilePath());
                $errors = error_get_last();
                $msg = Craft::t('imager', 'Error “{errorType}” encountered while attempting to download “{imageUrl}”: {errorMessage}', ['imageUrl' => $imageUrl, 'errorType' => $errors['type'], 'errorMessage' => $errors['message']]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }
        } else {
            $msg = Craft::t('imager', 'Looks like allow_url_fopen is off and cURL is not enabled. To download external files, one of these methods has to be enabled.');
            Craft::error($msg, __METHOD__);
            throw new ImagerException($msg);
        }
    }
166612
protected function image()
    {
        $locator = Grav::instance()['locator'];

        $file = $this->get('filepath');

        // Use existing cache folder or if it doesn't exist, create it.
        $cacheDir = $locator->findResource('cache://images', true) ?: $locator->findResource('cache://images', true, true);

        // Make sure we free previous image.
        unset($this->image);

        $this->image = ImageFile::open($file)
            ->setCacheDir($cacheDir)
            ->setActualCacheDir($cacheDir)
            ->setPrettyName($this->getImagePrettyName());

        return $this;
    }