public function testGetExtensionName()
 {
     $inputName = 'test_name';
     $_FILES[$inputName] = array('name' => 'test_file.dat', 'type' => 'somemime/type', 'tmp_name' => '/tmp/test_file', 'error' => UPLOAD_ERR_OK, 'size' => 100);
     $uploadedFile = CUploadedFile::getInstanceByName($inputName);
     $this->assertEquals("dat", $uploadedFile->getExtensionName(), 'Wrong extension name!');
     // reset and test a setup without file extension
     CUploadedFile::reset();
     $_FILES[$inputName]['name'] = 'test_file';
     $uploadedFile = CUploadedFile::getInstanceByName($inputName);
     $this->assertEquals("", $uploadedFile->getExtensionName(), 'Wrong extension name!');
 }
예제 #2
0
 public static function resetAndPopulateFilesArrayByFilePathAndName($arrayName, $filePath, $fileName)
 {
     assert('is_string($arrayName) && $arrayName != ""');
     // Not Coding Standard
     assert('is_string($filePath)  && $filePath  != ""');
     // Not Coding Standard
     assert('is_string($fileName)  && $fileName  != ""');
     // Not Coding Standard
     $_FILES = null;
     CUploadedFile::reset();
     $_FILES = array($arrayName => array('name' => $fileName, 'type' => ZurmoFileHelper::getMimeType($filePath), 'tmp_name' => $filePath, 'error' => UPLOAD_ERR_OK, 'size' => filesize($filePath)));
 }
예제 #3
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $class = get_class($this);
     if ($class == 'Accounts') {
         if (Accounts::model()->findByPk($this->id)) {
             $this->isNewRecord = false;
         }
     }
     $a = parent::save($runValidation, $attributes);
     if ($a) {
         //if (isset($_POST['Files'])) {
         //$this->attributes = $_POST['Files'];
         $tmps = CUploadedFile::getInstancesByName('Files');
         // proceed if the images have been set
         if (isset($tmps) && count($tmps) > 0) {
             Yii::log('saved', 'info', 'app');
             // go through each uploaded image
             $configPath = Yii::app()->user->settings["company.path"];
             foreach ($tmps as $image => $pic) {
                 $img_add = new Files();
                 $img_add->name = $pic->name;
                 //it might be $img_add->name for you, filename is just what I chose to call it in my model
                 $img_add->path = "files/";
                 $img_add->parent_type = get_class($this);
                 $img_add->parent_id = $this->id;
                 // this links your picture model to the main model (like your user, or profile model)
                 $img_add->save();
                 // DONE
                 if ($pic->saveAs($img_add->getFullFilePath())) {
                     // add it to the main model now
                 } else {
                     echo 'Cannot upload!';
                 }
             }
             if (isset($_FILES)) {
                 Yii::log(print_r($_FILES, true), 'info', 'app');
                 unset($_FILES);
                 $tmps = CUploadedFile::reset();
             }
             //}
         }
     }
     //endFile
     return $a;
 }
 public function setUp()
 {
     $_FILES = array();
     CUploadedFile::reset();
 }