模版
文件复制内容到剪贴板
代码:
<?php echo form_tag('media/upload', 'multipart=true') ?>
<?php echo input_file_tag('file') ?>
<?php echo submit_tag('Send') ?>
</form>action
复制内容到剪贴板
代码:
public function executeUpload()
{
$fileName = $this->getRequest()->getFileName('file');
$this->getRequest()->moveFile('file', sfConfig::get('sf_upload_dir').'/'.$fileName);
$this->redirect('media/show?filename='.$fileName);
} 默认上传到myproject/web/upload/目录下,可以修改config/config.php,改变上传目录
复制内容到剪贴板
代码:
sfConfig::add(array(
'sf_upload_dir_name' => $sf_upload_dir_name = 'uploads',
'sf_upload_dir' => sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_web_dir_name').DIRECTORY_SEPARATOR.$sf_upload_dir_name,
)); 显示上传的文件:
复制内容到剪贴板
代码:
<?php echo image_tag('/'.sfConfig::get('sf_upload_dir_name').'/'.$sf_params->get('filename')) ?>验证(Validation):
复制内容到剪贴板
代码:
methods:
post: [file]
names:
file:
required: Yes
required_msg: Please upload a file
validators: myFileValidator
file: true
myFileValidator:
class: sfFileValidator
param:
mime-types:
- 'image/jpeg'
- 'image/png'
- 'image/x-png'
- 'image/pjpeg'
mime-types-error: Only PNG and JPEG images are allowed
max_size: 2000
max_size_error: Max size is 2Mo