Esempio n. 1
0
    /**
     * Function loads an attachment, and switches between file as attachment and file as field.
     * The files are stored in web/upload dir containing WorkflowID/WorkflowversionID/md5(date_filename)
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeShowAttachment(sfWebRequest $request) {
        $versionid = $request->getParameter('versionid');
        $workflowid = $request->getParameter('workflowid');
        $attachmentid = $request->getParameter('attachmentid');
        $file = $request->getParameter('file');

        if ($file == 1) {
            $attachment = WorkflowSlotFieldFileTable::instance()->geFileById($attachmentid)->toArray(); // file from field
        }
        else {
            $attachment = WorkflowVersionAttachmentTable::instance()->getAttachmentsById($attachmentid)->toArray(); // file from attachment table
        }
        $filepath = sfConfig::get('sf_upload_dir') . '/' . $workflowid . '/' . $versionid . '/' . $attachment[0]['hashname'];
        $file = new File();

        $filecontent = $file->getFileContent($filepath); // open file and get content
        $contenttyoe = $file->getContenttype($attachment[0]['hashname']);

        $response = $this->getResponse();
        $response->clearHttpHeaders();

        $response->setHttpHeader('Content-Type', 'application/octet-stream'); // set content type of response
        $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename=' . $attachment[0]['filename']);
        $response->setHttpHeader('Content-Length', @filesize($filepath)); // add filesize
        $response->sendHttpHeaders(); // send the headers before the file
        $response->setContent($filecontent); // set file string
        return sfView::NONE;
    }
 public function buildAttachments(Doctrine_Collection $data, $templateversion_id) {
     $files = WorkflowVersionAttachmentTable::instance()->getAttachmentsByVersionId($templateversion_id)->toArray();
     $result = array();
     $a = 0;
     foreach($files as $file) {
         $result[$a]['filepath'] = sfConfig::get('sf_upload_dir') . '/' . $file['workflowtemplate_id'] . '/' . $file['workflowversion_id'] . '/' . $file['hashname'] ;
         $result[$a]['hashname'] = $file['hashname'];
         $result[$a]['filename'] = $file['filename'];
         $url = $this->serverUrl . '/file/ShowAttachment';
         $url .= '/workflowid/' .  $file['workflowtemplate_id'] . '/versionid/' . $file['workflowversion_id'] . '/attachmentid/' . $file['id'] . '/file/0';
         $result[$a]['link'] = '<a href="'.$url.'" target="_blank">'.$result[$a]['filename'].'</a>';
         $a++;
     }
     
     return $result;
 }