예제 #1
0
 public function actionGetRemoteImage()
 {
     $url = isset($_POST['url']) ? $_POST['url'] : die('图片地址不正确~');
     $info = UtilHelper::resourceLocalize($url);
     //        UtilHelper::dump($info);
     $model = new File();
     $model->name = $info['filename'];
     $model->ext = $info['extension'];
     $model->created = time();
     $model->size = $info['size'];
     $model->pid = Lookup::model()->getUserAdThemeAlbum(Yii::app()->user->id)->id;
     $model->mime = File::model()->getMimeType($model->ext, $info['mime']);
     $src = './public/favorite/' . $model->name . '.' . $model->ext;
     $target = File::model()->generateFileName($model, 'adtheme', true);
     //        UtilHelper::dump($model->attributes);
     if ($model->save()) {
         UtilFile::moveFile($src, $target);
         $result = array('id' => $model->id, 'path' => File::model()->generateFileName($model, 'adtheme', false));
         echo json_encode($result);
     }
 }
예제 #2
0
 /**
  * 复制文件
  *
  * @param string $fileUrl
  * @param string $aimUrl
  * @param boolean $overWrite 该参数控制是否覆盖原文件
  * @return boolean
  */
 function copyFile($fileUrl, $aimUrl, $overWrite = false)
 {
     if (!file_exists($fileUrl)) {
         return false;
     }
     if (file_exists($aimUrl) && $overWrite == false) {
         return false;
     } elseif (file_exists($aimUrl) && $overWrite == true) {
         UtilFile::unlinkFile($aimUrl);
     }
     $aimDir = dirname($aimUrl);
     UtilFile::createDir($aimDir);
     copy($fileUrl, $aimUrl);
     return true;
 }