Exemple #1
0
 public static function getInstance($key = "")
 {
     if (self::$_instance === null) {
         self::$_instance = new CloudService();
     }
     if ($key) {
         self::$_instance->setKey($key);
     }
     return self::$_instance;
 }
 public function actionConvert()
 {
     $files = UploadFile::model()->findAllByAttributes(array('storage' => 'cloud'));
     $cloud = CloudService::getInstance();
     foreach ($files as $file) {
         if (!$file->convertKey) {
             echo $file->path;
             echo $cloud->convert($file->path);
             echo "\n";
         }
     }
 }
$storage = $cloudStorageForm->storage;
?>

	<br />

	<div id="dxd-for-self"
		class="dxd-media-source <?php 
if ($model->mediaSource != "self") {
    echo 'dxd-hidden';
}
?>
">

		<?php 
if ($storage == 'cloud') {
    $cloudService = CloudService::getInstance("uploads/uploadFile/lesson/mediaId/" . DxdUtil::randCode(32));
    //	$cloudService = new CloudService();
    $this->widget('ext.uploadify.MUploadify', array('name' => 'file', 'buttonText' => '选择文件', 'auto' => true, 'uploader' => 'http://up.eduwind.com', 'formData' => array('token' => $cloudService->makeUploadToken(), 'key' => $cloudService->getKey()), 'onUploadSuccess' => "js:function(file, data, response) {\n\t\t\t   \t\t\t\t\tdataObj = JSON.parse(data);\n\t\t\t   \t\t\t\t\tif(data){\n\t\t\t  \t\t\t\t\t\t\$('#uploaded-file-{$model->id}').html('<span style=\\'text-success\\'>“' + file.name + '</span>”已经上传成功。');\n\t\t\t  \t\t\t\t\t\t\$.post('" . $this->createUrl('setMedia', array('lessonId' => $model->id)) . "',{name:file.name,mediaId:dataObj.id});\n\t\t\t\t\t\t\t\t\t}else{\n\t\t\t  \t\t\t\t\t\t\$('#uploaded-file-{$model->id}').html('<span style=\\'text-error\\'>“' + file.name + '</span>”上传失败。');\n    \t\t\t\t\t\t\t}\n\t\t\t\t\t}", 'onQueueComplete' => "js:function(queueData) {\n\t\t\t            \$('div#file').addClass('dxd-hidden');\n\t\t\t        }"));
    //    	$this->widget('ext.uploadify.MUploadify',CloudService::getInstance("uploads/uploadFile/lesson/mediaId/".DxdUtil::randCode(32))->getUploadifySetting());
    //    	CloudService::getInstance()->cloudService();
} else {
    $this->widget('ext.uploadify.MUploadify', array('name' => 'file', 'buttonText' => '选择文件', 'uploader' => $this->createUrl('upload', array('lessonId' => $model->id)), 'auto' => true, 'onUploadSuccess' => "js:function(file, data, response) {\n\t\t\t   \t\t\t\t\tif(data){\n\t\t\t  \t\t\t\t\t\t\$('#uploaded-file-{$model->id}').html('<span style=\\'text-success\\'>“' + file.name + '</span>”已经上传成功。');\n\t\t\t  \t\t\t\t\t}else{\n\t\t\t  \t\t\t\t\t\t\$('#uploaded-file-{$model->id}').html('<span style=\\'text-error\\'>“' + file.name + '</span>”上传失败。');\n    \t\t\t\t\t\t\t}\n\t\t\t\t\t        }", 'onQueueComplete' => "js:function(queueData) {\n\t\t\t            \$('div#file').addClass('dxd-hidden');\n\t\t\t        }"));
}
//	echo $form->hiddenField($model,'mediaId',array('id'=>'mediaId'));
?>
		<!-- 
    <div><pre><p id="uploadFileName" class="text-center text-info">还没有选择文件</p></pre></div>
     -->
		<br /> <em id='uploaded-file-<?php 
echo $model->id;
?>
Exemple #4
0
if ($model->file) {
    echo "已上传文件:" . $model->file->name;
}
?>
 
     	<br/><?php 
echo "最大允许上传文件" . $maxFileSize . "M";
?>
     	&nbsp;&nbsp;<?php 
echo CHtml::link('如何修改?', "http://eduwind.com/index.php?r=group/post&id=33", array('target' => '_blank'));
?>
     	-->
    
    <?php 
if ($storage == 'cloud') {
    $this->widget('ext.uploadify.MUploadify', CloudService::getInstance("uploads/uploadFile/lesson/mediaId/" . DxdUtil::randCode(32))->getUploadifySetting());
} else {
    $this->widget('ext.uploadify.MUploadify', array('name' => 'file', 'buttonText' => '选择文件', 'uploader' => $this->createUrl('lesson/uploadVideo', array('courseId' => $model->courseId)), 'auto' => true, 'onUploadSuccess' => "js:function(file, data, response) {\n\t\t\t   \t\t\t\t\tdataObj = JSON.parse(data);\n\t\t\t   \t\t\t\t\t\$('input#mediaId').val(dataObj.id);\n\t\t\t   \t\t\t\t\t\$('p#uploadFileName').html('文件“' + file.name + '”已经上传成功。<a id=\"reUpload\" href=\"javaScript:void(0)\">重新上传</a>');\n\t\t\t   \t\t\t\t\t\$('.uploadify').uploadify('settings','buttonText','再次上传');\n\t\t\t\t\t        }", 'onQueueComplete' => "js:function(queueData) {\n\t\t\t            \$('div#file').addClass('dxd-hidden');\n\t\t\t        }"));
}
echo $form->hiddenField($model, 'mediaId', array('id' => 'mediaId'));
?>
    
    <div><pre><p id="uploadFileName" class="text-center text-info">还没有选择文件</p></pre></div>
    
    </div>
    <div id="dxd-for-link" class="dxd-media-source <?php 
if ($model->mediaSource == "self") {
    echo 'dxd-hidden';
}
?>
">
Exemple #5
0
 protected function afterDelete()
 {
     $fullPath = Yii::app()->basePath . "/../" . $this->path;
     if (file_exists($fullPath) && $this->storage == "local") {
         return unlink($fullPath);
     } elseif ($this->storage == "cloud") {
         error_log("in upload file model");
         //删除文件
         $cloudService = CloudService::getInstance();
         $cloudService->deleteFile($this->path);
         //如果切片了,删除切片
         if ($this->convertStatus == "success") {
             $cloudService->deleteSlices($this->convertKey);
         }
     }
 }
<?php

/* @var $this LessonController */
/* @var $data Lesson */
?>




<div class="dxd-player">
	<div class="visible-desktop">
    <?php 
$file = $lesson->file;
if ($file && $file->storage == "local") {
    $src = Yii::app()->baseUrl . "/" . $lesson->file->path;
    $this->widget('ext.videojs.MVideoJsPlayer', array('flashvars' => array('src' => $src)));
} elseif ($file && $file->storage == "cloud") {
    $src = CloudService::getInstance()->getDownloadUrl($file->convertStatus == "success" ? $file->convertKey : $file->path);
    $this->widget('ext.grindplayer.MGrindPlayer', array('flashvars' => array('src' => $src)));
}
?>
    </div>

  </div> 
  
  <script type="text/javascript">

$('.dxd-player').on('contextmenu', function(e) {e.preventDefault();});
</script>
<div class="clearfix"></div>
 public function actionUploadUrl()
 {
     //首先应该判断是否有上传资格,如果没有,不返回
     //改为从CloudService取得,并从home取得
     echo json_encode(array('url' => CloudService::getInstance()->getUploadUrl()));
 }