Example #1
0
    protected function generate_response($content, $print_response = true) {
        if ($print_response) {

            //replace values with modified after file conversion
            foreach ($content['files'] as $file_item) {
                $file_item->url='';
                $file_item->thumbnailUrl='';
                $file_item->path= FileCache::updateFileInCache($file_item->path);

                $new_file_name = FileModification::getFileNameByPath(FileCache::getCacheFilePath($file_item->path));
                if ($new_file_name)  $file_item->name = $new_file_name ;

                //$new_file_ext = FileModification::getFileExtByPath(FileCache::getCacheFilePath($file_item->path));
                $file_item->type = 'application/pdf' ;

                $newcontent['files'][] = $file_item;
            }

            $content = $newcontent;
            $json = json_encode($content);
            $redirect = isset($_REQUEST['redirect']) ?
                stripslashes($_REQUEST['redirect']) : null;
            if ($redirect) {
                $this->header('Location: '.sprintf($redirect, rawurlencode($json)));
                return;
            }
            $this->head();
            if ($this->get_server_var('HTTP_CONTENT_RANGE')) {
                $files = isset($content[$this->options['param_name']]) ?
                    $content[$this->options['param_name']] : null;
                if ($files && is_array($files) && is_object($files[0]) && $files[0]->size) {
                    $this->header('Range: 0-'.(
                        $this->fix_integer_overflow(intval($files[0]->size)) - 1
                    ));
                }
            }
            $this->body($json);
        }
        return $content;
    }