From: avl Date: Thu, 11 Sep 2008 00:51:50 +0000 (+0300) Subject: Check image format for upload image file X-Git-Tag: 0.5~495 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=bdbb2254a622c4e1be31a1899785e6c2c606ecd4;p=ipf.git Check image format for upload image file --- diff --git a/ipf/form/field/file.php b/ipf/form/field/file.php index 646c6eb..a6205ac 100644 --- a/ipf/form/field/file.php +++ b/ipf/form/field/file.php @@ -69,24 +69,12 @@ function IPF_Form_Field_moveToUploadFolder($value, $params=array()) if (!move_uploaded_file($value['tmp_name'], $dest)) { throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); } - @chmod($dest, 0666); + @chmod($dest, IPF::get('file_permission')); return $name; } function IPF_Form_Field_removeFile($value, $params=array()) { - /* - $name = IPF_Utils::cleanFileName($value['name']); - $upload_path = IPF::get('upload_path', '/tmp'); - if (isset($params['upload_path'])) { - $upload_path = $params['upload_path']; - } - $dest = $upload_path.DIRECTORY_SEPARATOR.$name; - if (!move_uploaded_file($value['tmp_name'], $dest)) { - throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); - } - @chmod($dest, 0666); - */ return null; } diff --git a/ipf/form/field/image.php b/ipf/form/field/image.php index 0a35c70..8591f4b 100644 --- a/ipf/form/field/image.php +++ b/ipf/form/field/image.php @@ -2,4 +2,21 @@ class IPF_Form_Field_Image extends IPF_Form_Field_File{ public $widget = 'IPF_Form_Widget_Image'; + public $move_function = 'IPF_Form_Field_moveImageToUploadFolder'; } + +function IPF_Form_Field_moveImageToUploadFolder($value, $params=array()) +{ + $name = IPF_Form_Field_moveToUploadFolder($value, $params); + $upload_path = IPF::get('upload_path', '/tmp'); + if (isset($params['upload_path'])) { + $upload_path = $params['upload_path']; + } + $image = $upload_path.DIRECTORY_SEPARATOR.$name; + + if(!getimagesize($image)) + throw new IPF_Exception_Form(__('An error occured when upload the image.')); + + return $name; +} +