From 38179aa66e662b080d62398a1ab6856793b792b1 Mon Sep 17 00:00:00 2001 From: avl Date: Thu, 13 Aug 2009 18:34:20 +0300 Subject: [PATCH] 12 --- ipf/form/field/file.php | 19 ++++++++++++++++--- ipf/form/widget/fileinput.php | 10 +++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ipf/form/field/file.php b/ipf/form/field/file.php index 9948a6e..c3c3462 100644 --- a/ipf/form/field/file.php +++ b/ipf/form/field/file.php @@ -5,6 +5,7 @@ class IPF_Form_Field_File extends IPF_Form_Field public $widget = 'IPF_Form_Widget_FileInput'; public $move_function = 'IPF_Form_Field_moveToUploadFolder'; public $remove_function = 'IPF_Form_Field_removeFile'; + public $rename_function = 'IPF_Form_Field_renameFile'; public $max_size = 8388608; // 8MB public $move_function_params = array(); @@ -14,10 +15,15 @@ class IPF_Form_Field_File extends IPF_Form_Field IPF::loadFunction($this->remove_function); return call_user_func($this->remove_function, $value['data']); } + if (@$value['name']!=@$value['rename']){ + IPF::loadFunction($this->rename_function); + return call_user_func($this->rename_function, &$value); + } $value = $value['data']; - + if ($value['name']=='') return ''; + parent::clean($value); $errors = array(); @@ -69,7 +75,14 @@ function IPF_Form_Field_moveToUploadFolder($value, $params=array()) } -function IPF_Form_Field_removeFile($value, $params=array()) -{ +function IPF_Form_Field_removeFile($value, $params=array()){ return null; } + +function IPF_Form_Field_renameFile($value, $params=array()){ + $upload_path = IPF::getUploadPath($params); + $old_name = @$upload_path.DIRECTORY_SEPARATOR.$value['name']; + $new_name = @$upload_path.DIRECTORY_SEPARATOR.$value['rename']; + @rename($old_name, $new_name); + return @$value['rename']; +} diff --git a/ipf/form/widget/fileinput.php b/ipf/form/widget/fileinput.php index 5063255..edecf4c 100644 --- a/ipf/form/widget/fileinput.php +++ b/ipf/form/widget/fileinput.php @@ -16,7 +16,7 @@ class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input $value = $value['data']; if (is_string($value) && $value!=''){ if ($this->allow_extended){ - $sim = 'Currently: '.$value.''; + $sim = 'Currently: view'; if ($this->allow_delete) $sim .= ' |  '; $sim .= ' Change:'; @@ -36,13 +36,17 @@ class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input if ($data[$name.'_remove']==1) $remove = true; $res = array('data'=>$data[$name], 'remove'=>$remove); - return $res; + if (isset($data[$name.'_rename'])) + $res['rename'] = $data[$name.'_rename']; + if (isset($data[$name.'_name'])) + $res['name'] = $data[$name.'_name']; + return $res; } return null; } public function valueToFormData($name, $data){ - if (isset($data[$name])) { + if (isset($data[$name])) { $remove = false; if (isset($data[$name.'_remove'])) if ($data[$name.'_remove']==1) -- 2.49.0