我需要将所有上传的文件移到域中,并且所有网站都将位于另一个域中
但在同一服务器ip中,因此如何编辑上传过程以上传文件
直接到“文件域”?
例如:
网站域名:doamin.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);
}
....................
}
提前致谢
解决方法:
Dagon的意思是:
$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);
希望能有所帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。