html文件代码
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<!-- ajax文件上传开始 -->
< script type = "text/javascript" src = "/imageupload/jquery-1.10.2.min.js" ></ script >
< script type = "text/javascript" src = "/imageupload/layer/layer.js" ></ script >
< script type = "text/javascript" src = "/imageupload/ajaxupload.js" ></ script >
<!--ajax文件上传结束-->
<!--上传文件按钮列表开始-->
< input id = "requesturl" type = "hidden" value = "{:U('admin/upload/uploadfile')}" />
< input id = "ajaxuploadfile" type = "file" onchange = "filechange()" />
< input id = "filepathurl" type = "hidden" value = "" />
< input type = "button" value = "第一张" pathurl = "./Uploads/admin/trailer/" class = "uploadclass" />
< input type = "button" value = "第二张" pathurl = "./Uploads/admin/fdfdfd/" class = "uploadclass" />
< input type = "button" value = "第三张" pathurl = "./Uploads/admin/cdcdfd/" class = "uploadclass" />
<!--上传文件按钮列表结束-->
|
php文件代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/**
* 文件上传方法
*/
public function uploadfile(){
//单文件上传
$upload = new \Think\Upload(); // 实例化上传类
$upload ->maxSize = 100000000 ; // 设置附件上传大小
$upload ->exts = array ( 'jpg' , 'gif' , 'png' , 'jpeg' ); // 设置附件上传类型
$url = $_POST [ 'filepathurl' ];
if (! file_exists ( $url )){
mkdir ( $url ,0777,true);
}
$upload ->rootPath = $url ; // 设置附件上传根目录
// 上传单个文件
$info = $upload ->uploadOne( $_FILES [ 'postfilename' ]);
if (! $info ) {
echo json_encode( array ( 'bool' =>false, 'error' => $upload ->getError()));
} else {
$path = $info [ 'savepath' ]. $info [ 'savename' ];
echo json_encode( array ( 'bool' =>true, 'path' => $path ));
}
}
|
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持服务器之家!
原文链接:http://www.cnblogs.com/chung2017/p/congphp.html