示例#1
0
 protected function sendCsv($filename, array $rows, Zend_Controller_Response_Http $response, $delimiter = "\t")
 {
     $response->setHeader('Cache-Control', 'maxage=3600')->setHeader('Pragma', 'no-cache')->setHeader('Content-type', 'text/csv')->setHeader('Content-Disposition', 'attachment; filename=' . $filename);
     foreach ($rows as &$r) {
         if (is_array($r)) {
             $out = "";
             foreach ($r as $s) {
                 $out .= ($out ? $delimiter : "") . '"' . str_replace('"', "'", $s) . '"';
             }
             $out .= "\r\n";
             $r = $out;
         }
     }
     $response->appendBody(implode("", $rows));
 }
示例#2
0
 function render($path, Am_View $view)
 {
     $urlPath = $this->request->get('path', 'upload::');
     $list = array();
     foreach ($this->plugins as $pl) {
         $o = new stdclass();
         $o->title = $pl->getTitle();
         $o->link = $this->getUrl($pl->getPath(null));
         $list[$pl->getId()] = $o;
     }
     $view->plugins = $list;
     $view->description = $this->storage->getDescription();
     $view->active_plugin = $this->storage->getId();
     $view->path = $path;
     $view->currentUrl = $this->getUrl($path);
     $items = $actions = array();
     foreach ($this->storage->getItems($path, $actions) as $item) {
         switch (true) {
             case $item instanceof Am_Storage_File:
                 $item->_data_info = $item->info($this->secure);
                 $item->_link = $this->getUrl($this->storage->getPath($item->getPath()));
                 $items[] = $item;
                 break;
             case $item instanceof Am_Storage_Folder:
                 $item->_link = $this->getUrl($this->storage->getPath($item->getPath()));
                 $items[] = $item;
                 break;
         }
     }
     foreach ($actions as $item) {
         switch (true) {
             case $item instanceof Am_Storage_Action_Upload:
                 $item->_link = $this->getUrl($urlPath . '?action=upload');
                 $view->upload = $item;
                 break;
             case $item instanceof Am_Storage_Action_CreateFolder:
                 $item->_link = $this->getUrl($urlPath . '?action=create-folder');
                 $view->createfolder = $item;
                 break;
             case $item instanceof Am_Storage_Action_Refresh:
                 $item->_link = $this->getUrl($urlPath . '?action=refresh');
                 $view->refresh = $item;
                 break;
             case $item instanceof Am_Storage_Action_DeleteFile:
                 $item->_link = $this->getUrl($urlPath . '?action=delete-file&path=__PATH__');
                 $view->deletefile = $item;
                 break;
             default:
                 $actions[] = $item;
         }
     }
     $view->actions = $actions;
     $view->items = $items;
     $output = $view->render('admin/_storage-grid.phtml');
     $this->response->appendBody($output);
 }
示例#3
0
 public function run(Zend_Controller_Response_Abstract $response = null)
 {
     $args = array($this);
     $this->runCallback(self::CB_BEFORE_RUN, $args);
     if ($response === null) {
         $response = new Zend_Controller_Response_Http();
     }
     $this->response = $response;
     $action = $this->getCurrentAction();
     $this->request->setActionName($action);
     ob_start();
     $this->actionRun($action);
     if ($this->response->isRedirect() && $this->completeRequest->isXmlHttpRequest()) {
         $url = null;
         foreach ($response->getHeaders() as $header) {
             if ($header['name'] == 'Location') {
                 $url = $header['value'];
             }
         }
         $code = $response->getHttpResponseCode();
         // change request to ajax response
         $response->clearAllHeaders();
         $response->clearBody();
         $response->setHttpResponseCode(200);
         $response->setHeader("Content-Type", "application/json; charset=UTF-8", true);
         $response->setBody(Am_Controller::getJson(array('ngrid-redirect' => $url, 'status' => $code)));
         //throw new Am_Exception_Redirect($url);
     } else {
         $response->appendBody(ob_get_clean());
     }
     unset($this->response);
     return $response;
 }
示例#4
0
 /**
  * @see AM_Handler_Export_Storage_Interface::sendPackage()
  * @throws AM_Handler_Export_Storage_Exception
  */
 public function sendPackage()
 {
     $sFilePath = $this->_buildPackagePath() . DIRECTORY_SEPARATOR . $this->getPackage()->getPackageName();
     $sFileName = $this->getPackage()->getPackageDownloadName();
     if (!file_exists($sFilePath)) {
         throw new AM_Handler_Export_Storage_Exception(sprintf('File "%s" not found', $sFilePath));
     }
     $oResponse = new Zend_Controller_Response_Http();
     $oResponse->setHttpResponseCode(200);
     $oRequest = new Zend_Controller_Request_Http();
     $iFileSize = filesize($sFilePath);
     $sFileMtime = @gmdate("D, d M Y H:i:s", @filemtime($sFilePath)) . " GMT";
     $rFile = @fopen($sFilePath, 'rb');
     $sRange = $oRequest->get('HTTP_RANGE');
     //Trying to resume download according to the HTTP_RANGE header
     if (preg_match('/bytes=(\\d+)-(\\d*)/i', $sRange, $matches)) {
         $sRange = $matches[1];
     } else {
         $sRange = false;
     }
     if ($sRange) {
         fseek($rFile, $sRange);
         $oResponse->setHttpResponseCode(206);
         $oResponse->setHeader('Content-Range', sprintf('bytes %d-%d/%d', $sRange, $iFileSize - 1, $iFileSize));
     }
     $oResponse->setHeader('Content-Disposition', 'attachment; filename=' . $sFileName)->setHeader('Content-Length', $iFileSize - $sRange)->setHeader('Content-Type', 'application/octet-stream')->setHeader('Accept-Ranges', 'bytes')->setHeader('Last-Modified', $sFileMtime);
     while (!feof($rFile)) {
         $sBuffer = fread($rFile, 2048);
         $oResponse->appendBody($sBuffer);
     }
     fclose($rFile);
     $oResponse->sendResponse();
 }