Save uploaded file with any filename characters

First of all this is a very common problem, for more details see this post

I tried to solve this but there is no easy way (or it is not possible).

So the only way that I found is knowing the original character encoding

Suppose the encoding is the Greek, so in this case:

In your model that is related with this file (suppose the table of this model has the id and name_file columns, etc)

public $file;
 public function rules() {
        return array(
            array('file', 'file', 'types' => 'doc,pdf,docx,txt,xlsx,doc,xls,png,jpg,gif,rtf'),

	 public beforeSave() {
	      if (parent::beforeSave()) {
				$model->file = CUploadedFile::getInstance($model, 'file');   
				if ($model->file) {
					$name_file = $model->file->name;
					$model->name_file = $name_file;
					$name_file = iconv('UTF-8', 'greek//TRANSLIT//IGNORE', $model->name_file);
					$model->file->saveAs('images/' . $name_file );
					return true;
		   return true;
		   return false;

    public function getFile() {
		   $encodedFile = iconv('UTF-8', 'greek//TRANSLIT//IGNORE', $this->name_file);
		   $path = 'images/' . $encodedFile; 
		   if (file_exists($path))
			  Yii::app()->getRequest()->sendFile($model->name_file, file_get_contents($path));
			  throw new CHttpException(404,'The requested file does not exists.'); //or whatever you want because this function is a model method
    public function beforeDelete() {
        $path = 'images/' . $this->name_file;
        $path = iconv('UTF-8', 'greek//TRANSLIT//IGNORE', $path);
        return parent::beforeDelete();

In your controller

public function actionCreate()
        $model=new YourModel();
        $this->render('create', array('model'=>$model));

 public function actionView($id) {

The left code is similar to this wiki


If you want to save filenames in another encoding you have to change the greek to the corresponding encoding.

If you want to save filenames in variety encoding (for each file) you have to save the specific encoding into the record (in seperate column) and call the iconv on the fly with the appropriate parameter.