{
public $widget = 'IPF_Form_Widget_FileInput';
public $max_size = 20971520; // 20MB
+ public $file_permission = 0666;
+ public $uploadUrl = null;
+ public $uploadPath = null;
public $uploadTo = '';
+ function __construct($params = array())
+ {
+ $params['uploadUrl'] = IPF::getUploadUrl();
+ $params['uploadPath'] = IPF::getUploadPath();
+ parent::__construct($params);
+ }
+
protected function removeFile($data)
{
return null;
protected function getAbsolutePath($filename)
{
- $upload_root = IPF::getUploadPath() . DIRECTORY_SEPARATOR;
+ $upload_root = $this->uploadPath . DIRECTORY_SEPARATOR;
if ($this->uploadTo)
return $upload_root . $this->uploadTo . DIRECTORY_SEPARATOR . $filename;
else
protected function renameFile($old_name, $new_name)
{
- $upload_root = IPF::getUploadPath() . DIRECTORY_SEPARATOR;
+ $upload_root = $this->uploadPath . DIRECTORY_SEPARATOR;
@rename($upload_root . $old_name, $upload_root . $new_name);
return $new_name;
}
$dest = $this->getAbsolutePath($name);
if (!move_uploaded_file($data['tmp_name'], $dest))
throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.'));
- @chmod($dest, IPF::get('file_permission'));
+ @chmod($dest, $this->file_permission);
return $this->getRelativePath($name);
}
-}
+ protected function createWidget($args)
+ {
+ $widgetClass = $this->widget;
+ /** @var IPF_Form_Widget_FileInput $widget */
+ $widget = new $widgetClass($args);
+ $widget->uploadUrl = $this->uploadUrl;
+ return $widget;
+ }
+}
public $needs_multipart_form = true;
public $allow_extended = true;
public $allow_delete = true;
+ public $uploadUrl = null;
protected function viewCurrentValue($filename)
{
if ($filename)
- return Tag::a(array('target' => '_blank', 'href' => IPF::getUploadUrl().$filename), 'view')->html();
+ return Tag::a(array('target' => '_blank', 'href' => $this->uploadUrl.$filename), 'view')->html();
else
return '';
}
return $value;
}
}
-