UploadAction.class.php
<?php
class UploadAction extends BaseAction{
public function index(){
$this->display();
}
Public function upload(){
$today = date("Ymd");
$path = 'C:\ym\o2o\upload\\app\\'.$today;
$root = 'C:\\ym\\o2o\\upload\\app\\'.$today.'\\';
if(!is_dir($path)){
//echo "no";
mkdir($path);
}
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->saveRule = "";
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg','log');// 设置附件上传类型
$upload->savePath = $root;// 设置附件上传目录
if(!$upload->upload()) {// 上传错误提示错误信息
//$this->error($upload->getErrorMsg());
//echo $upload->getErrorMsg();
}else{// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
//var_dump($info);
$url = "http://localhost/upload/app/$today/".$info[0]['savename'];
//var_dump($info[0]["savepath"].$info[0]["name"]);
$data['headurl'] = $url;
M('user')->where(array('usertoken '=>$_REQUEST["usertoken"]))->save($data);
echo "success";
}
}
}
?>
index.php
<?php if(!defined('PigCms_VERSION')){ exit('deny access!');} ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name='apple-touch-fullscreen' content='yes'/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="format-detection" content="address=no"/>
<link rel="stylesheet" type="text/css" href="{pigcms{$static_path}css/common.css?210"/>
<link rel="stylesheet" type="text/css" href="{pigcms{$static_path}css/village.css?213"/>
<script type="text/javascript" src="{pigcms{:C('JQUERY_FILE_190')}" charset="utf-8"></script>
<script type="text/javascript" src="{pigcms{$static_path}js/idangerous.swiper.min.js" charset="utf-8"></script>
<script type="text/javascript" src="{pigcms{$static_path}js/fastclick.js" charset="utf-8"></script>
<script type="text/javascript" src="{pigcms{$static_path}/layer/layer.m.js" charset="utf-8"></script>
<script type="text/javascript" src="{pigcms{$static_path}js/common.js?210" charset="utf-8"></script>
</head>
<body>
<form method="post" action="{pigcms{:U('Upload/upload')}" refresh="true" enctype="multipart/form-data" >
<div class="btn">
<input type="text" name="usertoken"/>
<input type="file" class="input fl" name="img" style="width:145px;" placeholder="分类图片" tips="分类图片,尺寸为298*198的图标"/><br><br>
<input type="submit" name="dosubmit" value="提交" class="button" />
</div>
</form>
</body>
</html>