我需要移动域中所有上传的文件,所有网站都将在另一个域中
但在同一个服务器 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>
...............
Controller
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);
}
....................
}
提前致谢
最佳答案
达贡的意思是:
$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);
希望对你有帮助
关于php - 在同一台服务器上上传另一个域中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16687823/