微擎上传图片文件

html

<form id="form" class="form-horizontal" role="form" action="{php echo $this->createWebUrl('add');}" method="post" enctype="multipart/form-data">
<input data-rule="required" name="image" type="file">
<button id="sub" class="btn btn-primary btn-embossed">提交</button>
</form>

php

load()->func('file');
$filename = 'images/uplodes/' . md5(time().rand(0000,9999)) . '.' . explode('.', $_FILES['image']['name'])[1];
file_move($_FILES['image']['tmp_name'], MODULE_ROOT . '/' . $filename);

// var_dump(ATTACHMENT_ROOT . 'images/uplodes/'.$filename.explode('.',$_FILES['image']['name'])[1]);
$data = array(
  'image' => $filename,
);
$result = pdo_insert('vip', $data);
if (!empty($result)) {
  $uid = pdo_insertid();
  message('成功', $this->createWenUrl('vip'),'success');
}else{
  message('失败', $this->createWenUrl('vip'),'error');
}

遍历html

<img width="50px" src="{php echo MODULE_URL . $k['image']}" alt="" />

你可能感兴趣的:(微擎)