/**
  * @return void
  */
 public function testAddFileWithInvalidOption()
 {
     $filter = new Zend_Filter_File_Rename($this->_oldFile);
     try {
         $filter->addFile(1234);
         $this->fail();
     } catch (Zend_Filter_Exception $e) {
         $this->assertContains('Invalid options', $e->getMessage());
     }
 }
Exemple #2
0
 /**
  * This function is used to upload an image after resizing it.
  * @return string On success file name,on failure error message
  */
 public static function imageUploadAfterResize()
 {
     $max_size = 250;
     // maxim size for image file, in KiloBytes
     $allowtype = array('pdf', 'docx', 'rtf', 'odx', 'doc', 'txt', 'odt');
     /** Uploading the image **/
     $rezultat = '';
     $result_status = '';
     $result_msg = '';
     $type = end(explode(".", strtolower($_FILES['form_attachment']['name'])));
     if (in_array($type, $allowtype)) {
         if ($_FILES['form_attachment']['size'] <= $max_size * 1000) {
             //File Upload
             $logo = "";
             $path = FORM_ATTACHMENT_PREVIEW_PATH;
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->setDestination($path);
             //Constructor needs one parameter, the destination path is a good idea
             $renameFilter = new Zend_Filter_File_Rename($path);
             $files = $upload->getFileInfo();
             $logo = "";
             foreach ($files as $fileID => $fileInfo) {
                 if (!$fileInfo['name'] == '') {
                     $varaible = explode('.', $fileInfo['name']);
                     $extension = end($varaible);
                     $logo = md5(uniqid(rand(), true)) . '.' . $extension;
                     $renameFilter->addFile(array('source' => $fileInfo['tmp_name'], 'target' => $logo, 'overwrite' => true));
                 }
                 // add filters to Zend_File_Transfer_Adapter_Http
                 $upload->addFilter($renameFilter);
                 // receive all files
                 try {
                     $upload->receive();
                     //Image Resize
                     $frontobj = Zend_Controller_Front::getInstance();
                     if ($frontobj->getRequest()->getParam('form_attachment') != '') {
                         $image = new Zend_Resize($path . '/' . $logo);
                         $image->resizeImage(84, 84, 'crop');
                         $image->saveImage($path . '/' . $logo, 100);
                     }
                     //End Image Resize
                 } catch (Zend_File_Transfer_Exception $e) {
                     $rezultat = '';
                     $result_status = 'error';
                     $result_msg = $e->getMessage();
                 }
                 //upto here
                 $rezultat = $logo;
                 $result_status = 'success';
                 $result_msg = 'Uploaded Succesfully.';
             }
             //End File Upload
         } else {
             $rezultat = '';
             $result_status = 'error';
             $result_msg = 'The file exceeds the maximum permitted size ' . $max_size . ' KB.';
         }
     } else {
         $rezultat = '';
         $result_status = 'error';
         $result_msg = 'The file ' . $filename . ' has not an allowed extension.';
     }
     $result = array('result' => $result_status, 'img' => $rezultat, 'msg' => $result_msg);
     return $result;
 }