3

我需要移动域中所有上传的文件,并且所有网站都在另一个域中
但在同一服务器IP中,那么如何编辑上传过程以将文件直接上传到“文件域”?

前任:

网站域名:domin.com

文件域:myfiles.com

以正常方式这是我的代码:

看法

 ...........
    <?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'Cfiles-form',

            'enableAjaxValidation'=>false,
            'enableClientValidation'=>true,
            'clientOptions'=>array('validateOnSubmit'=>true), //This is very important


           'htmlOptions' => array('enctype' => 'multipart/form-data'),
    )); ?>
        <div class="row">
            <?php echo $form->labelEx($model,'file'); ?>
            <?php echo $form->fileField($model,'file'); ?>
            الملفات المسموحة : jpg,gif, png,pdf,rar,zip,doc,docx
            <?php echo $form->error($model,'file'); ?>
        </div>
    ...............

控制器

public function actionCreate()
    {

       ..................
.

        // Uncomment the following line if AJAX validation is needed
        $this->performAjaxValidation($model);

        if(isset($_POST['Cfiles']))
        {



            $model->attributes=$_POST['Cfiles'];
            $valdiate=$model->validate();


         /////// upload image functions 

         $rnd = rand(0,999984375);  // generate random number between 0-9999
         $model->attributes=$_POST['Cfiles']['file'];


            $uploadedFile=CUploadedFile::getInstance($model,'file');
        if(!empty($uploadedFile)){
            $ext=$uploadedFile->getExtensionName();
            $fileName = "isa$rnd.{$ext}";  // random number + file name
            }


             ////////// end 


            if($model->save()){

               $f_id=$model->primaryKey; 

               ................

                      if(!empty($uploadedFile))  // check if uploaded file is set or not
                {
                 $uploadedFile->saveAs(Yii::app()->basePath.'/../cfillaf/'.$fileName);  // upload image to server 
                  $model->file = $fileName;

                  $model->save(false);
               }   

  ....................

        }

提前致谢

4

1 回答 1

3

大衮的意思是:

$uploadedFile->saveAs(Yii::app()->basePath.'/../cfillaf/'.$fileName);

可以改成:

$uploadedFile->saveAs('http://www.myfiles.com/my_writable_image_dir/'.$fileName);

不要忘记确保 myfiles.com/my_writable_image_dir/ 是可写的。

但是,由于两个域都在同一台服务器上,您可以使用服务器路径来访问您的图像文件夹。像这样的东西:

$uploadedFile->saveAs(Yii::app()->basePath.'/../../../myfiles.com/public_html/my_writable_image_dir/'.$fileName);

希望有帮助

于 2013-05-24T14:18:23.020 回答