当前位置: 首页>>代码示例>>PHP>>正文


PHP Media::save方法代码示例

本文整理汇总了PHP中Media::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::save方法的具体用法?PHP Media::save怎么用?PHP Media::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Media的用法示例。


在下文中一共展示了Media::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveAndDeleteMedia

 private function saveAndDeleteMedia($type)
 {
     /** @var $model Media [ ] */
     $model = new Media();
     $mockRecord = $this->getMockRecord();
     $instruction = Deal::model()->findByPk($mockRecord['med_row']);
     $this->assertNotEmpty($instruction, "instruction not exist");
     $property = Property::model()->findByPk($instruction->dea_prop);
     $this->assertNotEmpty($property, "property not exist");
     $this->assertNotNull($property->addressId, "property has no address");
     $address = Address::model()->findByPk($property->addressId);
     $this->assertNotEmpty($address, " Address not exist");
     $model->setAttributes($this->getMockRecord());
     $model->file = $this->getMockCuploadedImage('image/jpeg', 1);
     if ($type == Media::TYPE_PHOTO) {
         $model->setCropFactor($this->getCropFactor());
     } elseif ($type == Media::TYPE_EPC || $type == Media::TYPE_FLOORPLAN) {
         $model->otherMedia = $type;
     }
     $this->assertTrue($model->validate(), "record not validated");
     $this->assertTrue($model->save(), "record not saved");
     foreach ($model->getImageSizes() as $imageSize) {
         $this->assertFileExists($model->getFullPath($imageSize), $imageSize . " does not exist");
     }
     $this->deleteMedia($model->med_id);
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:26,代码来源:MediaTest.php

示例2: saveMedia

 public static function saveMedia($file, $parentId, $type, $className, $isMain)
 {
     if ($file['name']) {
         $media = new Media();
         $media->setParentId($parentId);
         $media->setType($type);
         $media->setClassName($className);
         $media->setPath($file['name']);
         //retrive file extention
         $fileNameArr = explode('.', $file['name']);
         $fileExt = end($fileNameArr);
         $media->setExt($fileExt);
         if ($isMain) {
             $media->setIsMain(1);
         }
         $media->save();
         //Save file
         if ($type == MediaPeer::IMAGE) {
             // resize image
             $image = new sfThumbnail(800, 800);
             $image->loadFile($file['tmp_name']);
             //$image->save(sfConfig::get('sf_upload_dir')."/$parentId/".$file['name'], 'image/jpeg');
             $image->save(sfConfig::get('sf_upload_dir') . "/" . $media->getId() . "." . $media->getExt());
             // create thunmbnail
             $imageTh = new sfThumbnail(80, 80);
             $imageTh->loadFile($file['tmp_name']);
             $imageTh->save(sfConfig::get('sf_upload_dir') . "/th_" . $media->getId() . "." . $media->getExt());
         }
     }
 }
开发者ID:navid045,项目名称:maxlaptop,代码行数:30,代码来源:MediaPeer.php

示例3: getImage

function getImage($img)
{
    try {
        if (strpos($img, 'http://') !== false) {
            $original_url = $img;
            $pos = strrpos($img, ".");
            $ext = substr($img, $pos + 1);
            $media = new Media();
            $media->save();
            $fileName = $media->getId() . "." . $ext;
            $basePath = sfConfig::get('sf_web_dir') . "/media/upload/";
            file_put_contents($basePath . $fileName, file_get_contents($img));
            $mime = explode(";", Media::mime_content_type($basePath . $fileName));
            $mime = $mime[0];
            $media->setFilename($fileName);
            $media->setFiletype($mime);
            $media->setFiledirpath($basePath);
            $media->save(null, $o);
            chmod($basePath . $fileName, 0777);
            $media->resizeImage(null, 450);
            $media->resizeImage(1, 150);
        } elseif (base64_decode($img)) {
            $ext = "jpg";
            $media = new Media();
            $media->save();
            $fileName = $media->getId() . "." . $ext;
            $basePath = sfConfig::get('sf_web_dir') . "/media/upload/";
            file_put_contents($basePath . $fileName, base64_decode($img));
            $mime = explode(";", Media::mime_content_type($basePath . $fileName));
            $mime = $mime[0];
            $media->setFilename($fileName);
            $media->setFiletype($mime);
            $media->setFiledirpath($basePath);
            $media->save(null, $o);
            chmod($basePath . $fileName, 0777);
            $media->resizeImage(null, 450);
            $media->resizeImage(1, 150);
        }
    } catch (Exception $e) {
        $media->delete();
        FileHelper::Log("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]");
        echo_cms("CRON ERROR >>> Field : " . $k . " on item " . $o->getId() . "(" . $offer['originalid'] . ") is not a valid image. [" . $original_url . "]");
    }
}
开发者ID:kotow,项目名称:work,代码行数:44,代码来源:sfPakeUtils.php

示例4: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Media();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Media'])) {
         $model->attributes = $_POST['Media'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:jwerd,项目名称:coupon,代码行数:17,代码来源:MediaController.php

示例5: saveAssociatedMedia

 /**
  * Save uploaded file and add associated media object
  */
 public function saveAssociatedMedia($file)
 {
     if (!$file instanceof CUploadedFile) {
         return;
     }
     $fileAttribute = $this->fileAttribute;
     $media = new Media();
     $username = Yii::app()->user->getName();
     // file uploaded through form
     $tempName = $file->getTempName();
     $media->setAttributes(array('associationType' => $this->associationType, 'associationId' => $this->getAssociationId(), 'uploadedBy' => $username, 'createDate' => time(), 'lastUpdated' => time(), 'fileName' => preg_replace('/ /', '_', $file->getName()), 'mimetype' => $file->type), false);
     $media->resolveNameConflicts();
     if (!$media->save()) {
         throw new CException(implode(';', $media->getAllErrorMessages()));
     }
     if (!FileUtil::ccopy($tempName, "uploads/protected/media/{$username}/{$media->fileName}")) {
         throw new CException();
     }
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:22,代码来源:AssociatedMediaBehavior.php

示例6: insertMedia

 private function insertMedia($file)
 {
     /**
      * @var \yii\web\UploadedFile $file
      */
     $result = ['success' => false, 'message' => 'File could not be saved.'];
     if ($file->size > Yii::$app->params['maxUploadSize']) {
         $result['message'] = 'Max upload size limit reached';
     }
     $uploadTime = date("Y-m-W");
     $media = new Media();
     //TODO create your own model active record
     $media->filename = Inflector::slug(str_replace($file->extension, '', $file->name)) . '.' . $file->extension;
     $media->mimeType = $file->type;
     $media->byteSize = $file->size;
     $media->extension = $file->extension;
     $media->source = basename(\Yii::$app->params['uploadPath']) . '/' . $uploadTime . '/' . $media->filename;
     if (!is_file($media->source)) {
         //If saved upload the file
         $uploadPath = \Yii::$app->params['uploadPath'] . $uploadTime;
         if (!is_dir($uploadPath)) {
             mkdir($uploadPath, 0777, true);
         }
         if ($file->saveAs($uploadPath . '/' . $media->filename)) {
             //Save to media table
             if ($media->save(false)) {
                 $result['success'] = true;
                 $result['message'] = 'Upload Success';
                 $result['data'] = $media;
             } else {
                 $result['message'] = "Database record could not be saved.";
             }
         } else {
             $result['message'] = "File could not be saved.";
         }
     } else {
         $result['message'] = "File already exists.";
     }
     return $result;
 }
开发者ID:perminder-klair,项目名称:yii2-sir-trevor-js,代码行数:40,代码来源:UploadAction.php

示例7: populate

 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getDB()) != "DBOracle") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:mootools-forge,代码行数:101,代码来源:BookstoreDataPopulator.php

示例8: postMediaUpload

 /**
  * Upload images via the media block.
  */
 public function postMediaUpload()
 {
     foreach ($_FILES["images"]["error"] as $key => $error) {
         if ($error == UPLOAD_ERR_OK) {
             $name = md5(time() . microtime() . $key . 'alan' . $key . 'joey');
             $extension = explode('.', $_FILES['images']['name'][$key]);
             $path = public_path() . '/uploads/media/' . $name . '.' . end($extension);
             move_uploaded_file($_FILES["images"]["tmp_name"][$key], $path);
             $media = new Media();
             $media->name = $name . '.' . end($extension);
             $media->filename = $path;
             $media->save();
         }
     }
 }
开发者ID:Fash1,项目名称:Fash1,代码行数:18,代码来源:AdminController.php

示例9: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Topics();
     $fileCreation = false;
     if (isset($_FILES['upload']) || isset($_POST['Topics'])) {
         $data = array();
         $topicText = null;
         if (isset($_FILES['upload'])) {
             $fileCreation = true;
             $data = array('name' => $_POST['topicName']);
             $topicText = $_POST['topicText'];
         } else {
             if (isset($_POST['Topics'])) {
                 $data = $_POST['Topics'];
                 $topicText = $_POST['TopicReplies']['text'];
             }
         }
         $data['text'] = $topicText;
         $model->setX2Fields($data, false, true);
         if (isset($_POST['x2ajax'])) {
             $ajaxErrors = $this->quickCreate($model);
         } else {
             if ($model->save()) {
                 if ($fileCreation) {
                     $media = new Media();
                     $username = Yii::app()->user->getName();
                     // file uploaded through form
                     $temp = CUploadedFile::getInstanceByName('upload');
                     if ($temp && ($tempName = $temp->getTempName()) && !empty($tempName)) {
                         $name = $temp->getName();
                         $name = str_replace(' ', '_', $name);
                         $check = Media::model()->findAllByAttributes(array('fileName' => $name));
                         // rename file if there name conflicts by suffixing "(n)"
                         if (count($check) != 0) {
                             $count = 1;
                             $newName = $name;
                             $arr = explode('.', $name);
                             $name = $arr[0];
                             while (count($check) != 0) {
                                 $newName = $name . '(' . $count . ').' . $temp->getExtensionName();
                                 $check = Media::model()->findAllByAttributes(array('fileName' => $newName));
                                 $count++;
                             }
                             $name = $newName;
                         }
                     }
                     if (FileUtil::ccopy($tempName, "uploads/protected/media/{$username}/{$name}")) {
                         $media->associationType = 'topicReply';
                         $media->associationId = $model->originalPost->id;
                         $media->uploadedBy = $username;
                         $media->createDate = time();
                         $media->lastUpdated = time();
                         $media->fileName = $name;
                         $media->mimetype = $temp->type;
                         if ($media->save()) {
                             echo $model->id;
                             Yii::app()->end();
                         }
                     }
                 } else {
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             } elseif ($model->hasErrors('text')) {
                 Yii::app()->user->setFlash('error', 'Original post text cannot be blank.');
             }
         }
     }
     if (isset($_POST['x2ajax']) || isset($_FILES['upload'])) {
         $this->renderInlineForm($model);
     } else {
         $this->render('create', array('model' => $model));
     }
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:77,代码来源:TopicsController.php

示例10: actionCreateTheme

 /**
  * Create a new theme record in the Media table, prevent duplicate filenames.
  * If theme cannot be saved, error message object is returned.
  */
 public function actionCreateTheme($themeAttributes)
 {
     $themeAttributesArr = CJSON::decode($themeAttributes);
     if (!in_array('themeName', array_keys($themeAttributesArr)) || !in_array('themeName', array_keys($themeAttributesArr))) {
         echo self::getThemeErrorMsg();
     }
     $theme = new Media();
     $theme->setScenario('themeCreate');
     $theme->fileName = $themeAttributesArr['themeName'];
     $theme->private = $themeAttributesArr['private'];
     $theme->associationType = "theme";
     $theme->uploadedBy = Yii::app()->user->name;
     $theme->description = $themeAttributes;
     if (!$theme->save()) {
         echo self::getThemeErrorMsg();
     } else {
         echo self::getThemeSuccessMsg(array('id' => $theme->id));
     }
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:23,代码来源:ProfileController.php

示例11: upload

 public static function upload($fieldName, $to = "upload", $accept = array())
 {
     $request = sfContext::getInstance()->getRequest();
     if (strpos($fieldName, '/') === false) {
         $fileName = $request->getFileName($fieldName);
         $filePath = $request->getFilePath($fieldName);
         $error = $request->getFileValue($fieldName, "error");
         $real_file = false;
     } else {
         $fileName = $fieldName;
         $filePath = $fieldName;
         $error = 0;
         $real_file = true;
     }
     $fileType = self::mime_content_type($filePath);
     $fileTypes = explode(";", $fileType);
     $fileType = array_shift($fileTypes);
     if ($error = $request->getFileValue($fieldName, "error")) {
         switch ($error) {
             case 1:
                 $errorMsg = "UPLOAD_ERR_INI_SIZE";
                 break;
             case 2:
                 $errorMsg = "UPLOAD_ERR_FORM_SIZE";
                 break;
             case 3:
                 $errorMsg = "UPLOAD_ERR_PARTIAL";
                 break;
             case 4:
                 $errorMsg = "UPLOAD_ERR_NO_FILE";
                 break;
             case 5:
                 $errorMsg = "UPLOAD_ERR_NO_TMP_DIR";
                 break;
             case 6:
                 $errorMsg = "UPLOAD_ERR_CANT_WRITE";
                 break;
         }
     }
     if (!empty($accept)) {
         if (!empty($fileName) && !in_array($fileType, $accept)) {
             throw new Exception("UPLOAD_ERR_WRONG_FILE_TYPE");
         }
     }
     if ($request->getParameter('parent')) {
         $parent = Document::getDocumentInstance($request->getParameter('parent'));
     } else {
         $parent = Rootfolder::getRootfolderByModule('media');
     }
     $len = strlen(DIRECTORY_SEPARATOR);
     if (substr($to, -$len, $len) != DIRECTORY_SEPARATOR) {
         $to = $to . DIRECTORY_SEPARATOR;
     }
     //TODO
     $toPath = '/Applications/MAMP/trademark/httpdocs/media/upload/';
     //self::getMediaPath().$to;//
     $dirs = explode(DIRECTORY_SEPARATOR, $toPath);
     $thumbDir = '';
     foreach ($dirs as $dir) {
         $thumbDir .= $dir . DIRECTORY_SEPARATOR;
         try {
             if (!is_dir($thumbDir)) {
                 mkdir($thumbDir, 0777, true);
             }
         } catch (Exception $e) {
             throw new Exception("UPLOAD_ERR_CANT_CREATE_DIR");
         }
     }
     if (!$request->getParameter('id')) {
         if ($error) {
             throw new Exception($errorMsg);
         }
         $media = new Media();
         $media->save(null, $parent, false);
     } else {
         if ($error && $error != 4 && !empty($fileName)) {
             throw new Exception($errorMsg);
         }
         $media = Document::getDocumentInstance($request->getParameter('id'));
         if (!$media || get_class($media) != "Media") {
             $media = new Media();
             $media->save(null, $parent, false);
         } elseif ($error != 4) {
             if (file_exists($file = $media->getServerAbsoluteUrl())) {
                 @unlink($file);
             }
             if (file_exists($thumb = $media->getServerAbsoluteThumbUrl())) {
                 @unlink($thumb);
             }
         }
     }
     $ext = $media->getExtention($fileName);
     $extLen = strlen($ext);
     $saveFileName = $media->getId() . "." . $ext;
     if ($real_file) {
         @copy($fileName, $toPath . $saveFileName);
         @chmod($toPath . $saveFileName, 0777);
         @copy($fileName, $toPath . 'thumbs' . DIRECTORY_SEPARATOR . $saveFileName);
         @chmod($toPath . 'thumbs' . DIRECTORY_SEPARATOR . $saveFileName, 0777);
     } else {
//.........这里部分代码省略.........
开发者ID:kotow,项目名称:work,代码行数:101,代码来源:Media.php

示例12: testSynchGet

 /**
  * Test #11. SYNCH get an existent object.
  * @depends testDataWipedBeforeTest
  * @depends testGetExistent
  */
 public function testSynchGet()
 {
     global $testTripId1;
     global $testMediaId1;
     global $synchAuthToken;
     // Create the object and set attributes
     $object = new Media($testTripId1, $testMediaId1);
     $object->setType('photo');
     $object->setCaption('Caption 1');
     $object->setTimestamp('2015-09-30 12:03:45');
     $object->setLocation('location');
     $object->setWidth('900');
     $object->setHeight('600');
     $object->setDeleted('Y');
     // Save the object and confirm a row is added to the database
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $data = array('hash' => $object->getHash());
     $result = getApi('synchMedia.php', $data, $synchAuthToken);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertTrue(isset($result['mediaId']));
     $this->assertTrue(isset($result['created']));
     $this->assertTrue(isset($result['updated']));
     $this->assertTrue(isset($result['type']));
     $this->assertTrue(isset($result['caption']));
     $this->assertTrue(isset($result['timestamp']));
     $this->assertTrue(isset($result['location']));
     $this->assertTrue(isset($result['width']));
     $this->assertTrue(isset($result['height']));
     $this->assertTrue(isset($result['deleted']));
     $this->assertTrue(isset($result['hash']));
     $this->assertEquals($testTripId1, $result['tripId']);
     $this->assertEquals($testMediaId1, $result['mediaId']);
     $this->assertEquals($object->getCreated(), $result['created']);
     $this->assertEquals($object->getUpdated(), $result['updated']);
     $this->assertEquals('photo', $result['type']);
     $this->assertEquals('Caption 1', $result['caption']);
     $this->assertEquals('2015-09-30 12:03:45', $result['timestamp']);
     $this->assertEquals('location', $result['location']);
     $this->assertEquals('900', $result['width']);
     $this->assertEquals('600', $result['height']);
     $this->assertEquals('Y', $result['deleted']);
     $this->assertEquals($object->getHash(), $result['hash']);
 }
开发者ID:egrivel,项目名称:vacationblog,代码行数:50,代码来源:MediaApiTest.php

示例13: catch

} catch (Exception $e) {
    die("Error test date/time: " . $e->__toString());
}
// Handle BLOB/CLOB Columns
// ------------------------
try {
    print "\nTesting the BLOB/CLOB columns\n";
    print "-------------------------------\n\n";
    $blob_path = dirname(__FILE__) . '/etc/lob/tin_drum.gif';
    $blob2_path = dirname(__FILE__) . '/etc/lob/propel.gif';
    $clob_path = dirname(__FILE__) . '/etc/lob/tin_drum.txt';
    $m1 = new Media();
    $m1->setBook($phoenix);
    $m1->setCoverImage(file_get_contents($blob_path));
    $m1->setExcerpt(file_get_contents($clob_path));
    $m1->save();
    $m1_id = $m1->getId();
    print "Added Media collection [id = {$m1_id}].\n";
    print "Looking for just-created mediat by PK (={$m1_id}) .... ";
    try {
        $m1_lookup = MediaPeer::retrieveByPk($m1_id);
    } catch (Exception $e) {
        print "ERROR!\n";
        die("Error retrieving media by pk: " . $e->__toString());
    }
    if ($m1_lookup) {
        print "FOUND!\n";
    } else {
        print "NOT FOUND :(\n";
        die("Couldn't find just-created media item: media_id = {$m1_id}");
    }
开发者ID:yasirgit,项目名称:afids,代码行数:31,代码来源:bookstore-test.php

示例14: save

 public function save($runValidation = true, $attributes = null)
 {
     if ($this->photo) {
         // save related photo record
         $transaction = Yii::app()->db->beginTransaction();
         try {
             // save the event
             $ret = parent::save($runValidation, $attributes);
             if (!$ret) {
                 throw new CException(implode(';', $this->getAllErrorMessages()));
             }
             // add media record for file
             $media = new Media();
             $media->setAttributes(array('fileName' => $this->photo->getName(), 'mimetype' => $this->photo->type), false);
             $media->resolveNameConflicts();
             if (!$media->save()) {
                 throw new CException(implode(';', $media->getAllErrorMessages()));
             }
             // save the file
             $tempName = $this->photo->getTempName();
             $username = Yii::app()->user->getName();
             if (!FileUtil::ccopy($tempName, "uploads/protected/media/{$username}/{$media->fileName}")) {
                 throw new CException();
             }
             // relate file to event
             $join = new RelationshipsJoin('insert', 'x2_events_to_media');
             $join->eventsId = $this->id;
             $join->mediaId = $media->id;
             if (!$join->save()) {
                 throw new CException(implode(';', $join->getAllErrorMessages()));
             }
             $transaction->commit();
             return $ret;
         } catch (CException $e) {
             $transaction->rollback();
             return false;
         }
     } else {
         return parent::save($runValidation, $attributes);
     }
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:41,代码来源:Events.php

示例15: testLongText

 /**
  * Extra test
  * Make sure that a long text is saved in the media, one that has
  * at least more than 256 characters.
  * @depends testSaveEmptyObject
  * @depends testSetAttributes
  */
 public function testLongText()
 {
     global $testTripId1, $testMediaId1;
     $longText = "This is a long text. This is a very long text. This is a ver, very long text. In fact, this text will just go on and on and on, for up to 400 characters. So when we set and retrieve this text, we will know for sure that the system supports these long texts. Of course, if this fails, we won't know any such thing for sure. Would that be to happen, we will have to go and spend some quality debugging time with the system.";
     $object = new Media($testTripId1, $testMediaId1);
     $object->setCaption($longText);
     $this->assertTrue($object->save());
     $object = new Media($testTripId1, $testMediaId1);
     $this->assertEquals($longText, $object->getCaption());
 }
开发者ID:egrivel,项目名称:vacationblog,代码行数:17,代码来源:MediaTest.php


注:本文中的Media::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。