|
发表于 2011-9-7 09:10:17
|
显示全部楼层
夏天很热 发表于 2011-9-7 09:02
上面的代码变得好奇怪。。各位将就看看
这是我以前使用的一个片段,注意输出的东西要符合xh的开发规范
PHP复制代码
$config['upload_path'] = FCPATH .setting ('attachment_dir').'/'.date('Y/m',$now).'/';
if(!is_dir($config['upload_path']))
{
if(!mkdir($config['upload_path'], 0755, true))
{
echo '{"err":"文件创建失败!","msg":""}';return;
}
}
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name'] = $now;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('filedata'))
{
echo '{"err":"上传失败!","msg":""}';return;
}
else
{
$uploaded = $this->upload->data();
$realname = explode(".",$_FILES['filedata']['name']);
$data['type'] = strtolower(array_pop($realname));
$data['realname'] = implode('.',$realname);
$data['name'] = $uploaded['file_name'];
$data['posttime'] = now ();
$data['uid'] = $GLOBALS['agent']->agent_id;
$data['image'] = (in_array($data['type'],array('jpg','gif','png','jpeg','bmp'))) ? 1 : 0;
$data['model'] = ($type == 'sell' ? 1 : 2);
$data['foler'] = date('Y/m',$now);
$data['from'] = 0;
$data['content'] = $id;
$this->db->insert('dili_attachments',$data);
echo '{"err":"","msg":"'.base_url ().str_replace(FCPATH ,'',$config['upload_path']).$uploaded['file_name'].'"}';
}
复制代码 |
|