我想上传名称中包含特殊字符的文件(如@,#,!,〜等)。如何允许带有这些字符的文件名。我的代码是:
public function actionAddImage()
{
$model=new Gallery;
$this->pageTitle = CHtml::encode(Yii::app()->name).' :: Add Image';
if(isset($_POST['Gallery']))
{
$rnd = rand(0,9999);
$model->attributes=$_POST['Gallery'];
$uploadedFile = CUploadedFile::getInstance($model,'image');
$fileName = "{$rnd}-{$uploadedFile}";
$model->image = $fileName;
$model->description = $_POST['Gallery']['description'];
if($model->save())
{
$uploadedFile->saveAs(Yii::getPathOfAlias('webroot').'/upload/'.$fileName); // image will uplode to rootDirectory/banner/
//thumbmail---------------start---
Yii::app()->thumb->setThumbsDirectory('/upload/original/');
Yii::app()->thumb->load(Yii::getPathOfAlias('webroot').'/upload/'.$fileName)->resize(538,359)->save($fileName);
Yii::app()->thumb->setThumbsDirectory('/upload/thumb/');
Yii::app()->thumb->load(Yii::getPathOfAlias('webroot').'/upload/'.$fileName)->resize('0','110')->save($fileName);
Yii::app()->thumb->setThumbsDirectory('/upload/thumb_70/');
Yii::app()->thumb->load(Yii::getPathOfAlias('webroot').'/upload/'.$fileName)->resize('0',70)->save($fileName);
Yii::app()->user->setFlash('employee','Image has been added successfully');
$this->redirect(array('ManageGalleries'));
}
}
$this->layout = "loginMain";
$this->render('create',array(
'model'=>$model,
));
}
当我尝试上传包含特殊字符的文件时,不上传文件。 请帮助我如何允许这个文件名。