/** * Provide a file for download * * @return bool true on success else false */ function perform() { //Get the demanded attachment and send it to the client //get the top requested email list attachment folder M(MOD_EARCHIVE, 'get_list', array('var' => 'tpl_list', 'lid' => (int) $_GET['lid'], 'fields' => array('folder'))); //get the requested message attachment folder M(MOD_EARCHIVE, 'get_message', array('var' => 'tpl_msg', 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('folder'))); //get the attachment file name, type M(MOD_EARCHIVE, 'get_attach', array('var' => 'tpl_attach', 'aid' => (int) $_GET['aid'], 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('file', 'type'))); // set params to send http header and content $this->B->attach_params = array('file' => SF_RELATIVE_PATH . '/data/earchive/' . $this->B->tpl_list['folder'] . '/' . $this->B->tpl_msg['folder'] . '/' . stripslashes($this->B->tpl_attach['file']), 'contenttype' => $this->B->tpl_attach['type'], 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, stripslashes($this->B->tpl_attach['file']))); // stop output buffering // we dont need those headers which has been allready sended // while (@ob_end_clean()) { } // send header and content $error = HTTP_Download::staticSend($this->B->attach_params, false); if (TRUE !== $error) { trigger_error($error->message . " " . $this->B->attach_params['file'] . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR); } exit; // stop application here return TRUE; }
protected function runUntrustedAction($action) { switch ($action) { case 'backup': include_once 'HTTP/Download.php'; include_once 'Archive/Tar.php'; if (!$this->data_engine->dump(TIP::buildDataPath('dump'))) { TIP::notifyError('backup'); return false; } $tar_file = TIP::buildCachePath($this->id . '-' . TIP::formatDate('date_sql') . '.tar.gz'); $tar_object = new Archive_Tar($tar_file, 'gz'); $result = $tar_object->createModify(TIP::buildDataPath(), '', TIP::buildPath()); unset($tar_object); if ($result !== true) { return false; } HTTP_Download::staticSend(array('file' => $tar_file, 'contenttype' => 'application/x-gzip', 'contentdisposition' => HTTP_DOWNLOAD_ATTACHMENT)); exit; } return null; }
} break; case 'company_logo': Debug::Text('Company Logo...', __FILE__, __LINE__, __METHOD__, 10); $cf = new CompanyFactory(); $file_name = $cf->getLogoFileName($current_company->getId()); Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10); if ($file_name != '' and file_exists($file_name)) { $params['file'] = $file_name; $params['cache'] = TRUE; } break; case 'primary_company_logo': Debug::Text('Primary Company Logo...', __FILE__, __LINE__, __METHOD__, 10); $cf = new CompanyFactory(); $file_name = $cf->getLogoFileName(PRIMARY_COMPANY_ID); Debug::Text('File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10); if ($file_name != '' and file_exists($file_name)) { $params['file'] = $file_name; $params['cache'] = TRUE; } break; default: break; } if (isset($params)) { HTTP_Download::staticSend($params); } else { echo "File does not exist, unable to download!<br>\n"; Debug::writeToLog(); }
/** * Sends the buffered data to the browser. * * @param string $filename The filename for the output file. * @param boolean $inline True if inline, false if attachment. */ function output($filename = 'unknown.pdf', $inline = false) { /* Check whether the buffer has been flushed already. */ if ($this->_flushed) { return $this->raiseError('The buffer has been flushed already, don\'t use output() in combination with flush().'); } /* Check whether file has been closed. */ if ($this->_state < 3) { $result = $this->close(); if (is_a($result, 'PEAR_Error')) { return $result; } } /* Check if headers have been sent. */ if (headers_sent()) { return $this->raiseError('Unable to send PDF file, some data has already been output to browser'); } /* If HTTP_Download is not available return a PEAR_Error. */ if (!(include_once 'HTTP/Download.php')) { return $this->raiseError('Missing PEAR package HTTP_Download'); } /* Params for the output. */ $disposition = $inline ? HTTP_DOWNLOAD_INLINE : HTTP_DOWNLOAD_ATTACHMENT; $params = array('data' => $this->_buffer, 'contenttype' => 'application/pdf', 'contentdisposition' => array($disposition, $filename)); /* Output the file. */ return HTTP_Download::staticSend($params); }
/** * Обработчик действия: Экспорт каталога. */ function Export() { @set_time_limit(0); mk_dir("files/" . DOMAIN . "/tmp"); clearDir("files/" . DOMAIN . "/tmp"); require_once "Structures/DataGrid.php"; require_once "Structures/DataGrid/DataSource/Array.php"; require_once "Structures/DataGrid/Renderer/CSV.php"; $categories = array(); $fields = array(); $all = array(); A::$DB->query("SELECT * FROM " . SECTION . "_cols ORDER BY sort"); $i = 0; while ($row = A::$DB->fetchRow()) { if ($row['type'] == 'select' || $row['type'] == 'mselect') { if ($row['idvar'] = A::$DB->getOne("SELECT property FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' AND field=?", $row['field'])) { $row['vars'] = loadList($row['idvar']); foreach ($row['vars'] as $j => $name) { if (is_array($name) && isset($name['name'])) { $row['vars'][$j] = $name['name']; } } } } $row['id'] = $i++; $all[$row['field']] = $row; if (preg_match("/^category([0-9]{1})\$/i", $row['field'], $matches)) { $row['level'] = $matches[1]; $categories[$row['field']] = $row; } else { $fields[$row['field']] = $row; } } A::$DB->free(); $renderer = new Structures_DataGrid_Renderer_CSV(); $renderer->setOptions(array('delimiter' => ';', 'enclosure' => '"', 'saveToFile' => true, 'useQuotes' => true, 'filename' => "files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . ".csv")); $renderer->init(); $datasource = new Structures_DataGrid_DataSource_Array(); $datagrid = new Structures_DataGrid(); $datagrid->bindDataSource($datasource); $datagrid->attachRenderer(&$renderer); $i = 0; $header = array(); foreach ($all as $field => $frow) { $header[$i++] = array('field' => $field, 'label' => mb_convert_encoding($frow['caption'], "Windows-1251", "UTF-8")); } $renderer->buildHeader($header); $cats = array(); $this->getCategories($cats); $i = 0; foreach ($cats as $id => $category) { A::$DB->query("SELECT * FROM " . SECTION . "_catalog WHERE idcat={$id} ORDER BY name"); while ($row = A::$DB->fetchRow()) { $crow = array(); for ($j = 0; $j < count($all); $j++) { $crow[$j] = ""; } foreach ($categories as $field => $frow) { if (isset($category['parents'][$frow['level']])) { $crow[$frow['id']] = mb_convert_encoding($category['parents'][$frow['level']], "Windows-1251", "UTF-8"); } } foreach ($fields as $field => $frow) { switch ($frow['type']) { default: $crow[$frow['id']] = isset($row[$field]) ? mb_convert_encoding($row[$field], "Windows-1251", "UTF-8") : ''; break; case 'select': $crow[$frow['id']] = !empty($frow['vars'][$row[$field]]) ? mb_convert_encoding($frow['vars'][$row[$field]], "Windows-1251", "UTF-8") : ""; break; case 'mselect': $row[$field] = explode(',', $row[$field]); foreach ($row[$field] as $j => $value) { $row[$field][$j] = !empty($frow['vars'][(int) $value]) ? mb_convert_encoding($frow['vars'][(int) $value], "Windows-1251", "UTF-8") : ""; } $crow[$frow['id']] = implode(', ', $row[$field]); break; case 'float': $crow[$frow['id']] = round($row[$field], 2); break; case 'image': if (preg_match("/^idimg([0-9]+)\$/i", $field, $mathes)) { $sort = $mathes[1]; $images = A::$DB->getCol("SELECT path FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem=" . $row['id'] . " ORDER BY sort"); $crow[$frow['id']] = isset($images[$sort]) ? basename($images[$sort]) : ""; } break; case 'file': if (preg_match("/^idfile([0-9]+)\$/i", $field, $mathes)) { $sort = $mathes[1]; $files = A::$DB->getCol("SELECT path FROM " . DOMAIN . "_files WHERE idsec=" . SECTION_ID . " AND iditem=" . $row['id'] . " ORDER BY sort"); $crow[$frow['id']] = isset($files[$sort]) ? basename($files[$sort]) : ""; } break; } } if (isset($fields['mprice']) && isset($fields['price'])) { $mprices = !empty($row['mprices']) ? unserialize($row['mprices']) : array(); foreach ($mprices as $mp) { $crow[$fields['mprice']['id']] = mb_convert_encoding($mp['name'], "Windows-1251", "UTF-8"); $crow[$fields['price']['id']] = (double) $mp['price']; $renderer->buildRow($i++, $crow); } if (empty($mprices)) { $renderer->buildRow($i++, $crow); } } else { $renderer->buildRow($i++, $crow); } } A::$DB->free(); } $renderer->render(); $renderer->finalize(); if (filesize($file = "files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . '.csv') > 1024 * 2000) { return outArchive("files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . ".tar.gz", $file); } else { require_once 'HTTP/Download.php'; $params = array('file' => $file, 'contenttype' => 'text/csv', 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, basename($file))); HTTP_Download::staticSend($params, false); } }
<?php if (!defined('SF_SECURE_INCLUDE')) { exit; } //Get the demanded attachment and send it to the client include_once 'HTTP/Download.php'; //get the top requested email list attachment folder $B->M(MOD_MAILARCHIVER, MAILARCHIVER_LIST, array('var' => 'list', 'lid' => (int) $_GET['lid'], 'fields' => array('folder'))); //get the requested message attachment folder $B->M(MOD_MAILARCHIVER, MAILARCHIVER_MESSAGE, array('var' => 'msg', 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('folder'))); //get the attachment file name, type $B->M(MOD_MAILARCHIVER, MAILARCHIVER_ATTACH, array('var' => 'attach', 'aid' => (int) $_GET['aid'], 'mid' => (int) $_GET['mid'], 'lid' => (int) $_GET['lid'], 'fields' => array('file', 'type'))); // send http header and content $params = array('file' => './data/mailarchiver/' . $B->list['folder'] . '/' . $B->msg['folder'] . '/' . stripslashes($B->attach['file']), 'contenttype' => $B->attach['type'], 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, stripslashes($B->attach['file']))); $error = HTTP_Download::staticSend($params, false); if (TRUE !== $error) { trigger_error($error->message . " " . $params['file'] . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR); } exit;
/** * Stream the original file from anywhere on the user's PC. This function will serve the original file * and offer ranges for seeking through the content. */ private function stream_original() { $this->log('Sending File using Pear HTTP Download'); $params = array('File' => $this->filename, 'ContentType' => $this->source_type, 'BufferSize' => 32000, 'ContentDisposition' => array(HTTP_DOWNLOAD_INLINE, $this->source_basename)); $error = HTTP_Download::staticSend($params, false); }
<?php /* attach Template. See also /view/class.view_attach.php */ ?> <?php /* Only allow calling this template from whithin the application */ if (!defined('SF_SECURE_INCLUDE')) { exit; } ?> <?php // stop output buffering // we dont need those headers which has been allready sended // while (@ob_end_clean()) { } // send header and content $error = HTTP_Download::staticSend($B->attach_params, false); if (TRUE !== $error) { trigger_error($error->message . " " . $B->attach_params['file'] . "\n\nFILE: " . __FILE__ . "\nLINE: " . __LINE__, E_USER_ERROR); } exit;