我们使用微擎图片上传函数上传图片示例如下:
//上传图片
$id = intval($_GPC['id']);
//文件上传函数
load()->func('file');
//如果图片目录不存在就创建目录
$filepath = IA_ROOT . "/attachment/images/" . $_W['uniacid'] . "/" . date('Y', time()) . "/" . date('m', time());
mkdirs($filepath);
$res = file_upload($_FILES['file'], 'image');
if ($res['success'] == true) {
pdo_update('wc_lifebuy_merchant', array('logo'=>$res['path']), array('id'=>$id));
return $this->result(0, '上传成功', array('path'=>$res['path']));
} else {
return $this->result(1, '上传失败', array());
}
$filepath
是我们定义的图片上传的路径,使用mkdirs();
函数创建目录。