require_once MESSAGE_PATH . 'zh/zh_calendar_message.php'
require_once "function_common/user_function.php"
require_once "function_common/public_function.php"
global $DB
$sql_time = microtime ( true )
//$uid = $self_userid
//保存图片
$json_result ['status'] = 0
$path = 'upfile'
$json_result ['status'] = 0
$json_result ['successmsg'] = '上传失败'
if (isset ( $_FILES ['imageZip'] )) {
$upfile = 'upfile/' . $_FILES ['imageZip'] ['name']
if (! @file_exists ( $path )) {
@mkdir ( $path )
}
$result = @move_uploaded_file ( $_FILES ['imageZip'] ['tmp_name'], $upfile )
if (! $result) {
$json_result ['status'] = 0
$json_result ['successmsg'] = '上传失败'
$json_result ['datas'] = array ('savePath' => $upfile )
exit ( json_encode ( $json_result ) )
}
}
$json_result ['status'] = 1
$json_result ['datas'] = array ('savePath' => $upfile )
就这么写:上传 *** 作
ThinkPHP文件上传 *** 作使用Think\Upload类,假设前面的表单提交到当前控制器的upload方法,我们来看下upload方法的实现代码:
public function upload(){$upload = new \Think\Upload()// 实例化上传类$upload->maxSize = 3145728 // 设置附件上传大小$upload->exts = array('jpg', 'gif', 'png', 'jpeg')// 设置附件上传类型$upload->rootPath = './Uploads/'// 设置附件上传根目录$upload->savePath = ''// 设置附件上传(子)目录// 上传文件 $info = $upload->upload() if(!$info) {// 上传错误提示错误信息$this->error($upload->getError()) }else{// 上传成功$this->success('上传成功!') }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)