【微信小程序】多图片上传

Continue Read..

点击查看原图

 

 

HTML

 

<view class="picture_list">
<view wx:for="{{upload_picture_list}}" class="picture_item">
<image wx:if="{{item.upload_percent < 100}}" src="{{item.path}}" mode="aspectFill"></image>
<image wx:if="{{item.upload_percent == 100}}" src="{{item.path_server}}" mode="aspectFill"></image>
<view class="upload_progress" wx:if="{{item.upload_percent < 100}}">
{{item.upload_percent}}%
</view>
</view>
<view class="picture_item">
<image src="../../../resources/images/btn_uploadpic.png" bindtap="uploadpic" mode="aspectFill"></image>
</view>

</view>


CSS

.picture_list{
padding:20px;
display:flex;
flex-direction: row;
flex-wrap:wrap;
justify-content:flex-start;
align-items:flex-start;
align-content:flex-start;
}
.picture_item{margin:10px;position:relative;width:160rpx;height:160rpx;}
.upload_progress{position:absolute;top:0;left:0;opacity:0.7;background-color:#000;color:#fff;width:160rpx;height:160rpx;text-align:center;line-height:160rpx;font-size:12px;}
.picture_item image{width:160rpx;height:160rpx;}


js


var app = require('../../../resources/js/uploadimg.js');
Page({
data:{
upload_pictrue_list:[]
},
uploadpic : function (e){
var that = this;
var upload_picture_list = that.data.upload_pictrue_list;
wx.chooseImage({
count:9,
sizeType:['original','compressed'],
sourceType:['album','camera'],
success: function(res) {
//返回选定照片的本地文件路径,tempFilePath可以作为img标签的src属性
var tempFiles = res.tempFiles;
//循环把图片加入上传列表
for(var i in tempFiles){
tempFiles[i]['upload_percent'] = 0;
tempFiles[i]['path_server'] = "";
upload_picture_list.push(tempFiles[i]);
}
that.setData({
upload_picture_list : upload_picture_list
});
//循环把图片上传到服务器,并显示进度
for(var i in upload_picture_list){
if(upload_picture_list[i]['upload_percent'] == 0){
app.upload_file_server(that,upload_picture_list,i);
}
}
},
})
},



})


uploadimg.js

var urlStr = 'http://www.xxx.com';
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
function upload_file_server(that,upload_picture_list,j){
console.log("开始上传"+ j + "图片到服务器");
console.log(upload_picture_list[j]);
var upload_task = wx.uploadFile({
url: urlStr + '/testUpload.php',
filePath: upload_picture_list[j]['path'],//上传的文件本地地址,
name: 'file',
header: { "Content-Type": "multipart/form-data" },
fromData: { 'path': 'wxchat', 'session_token': wx.getStorageSync('session_token')},
success:function(res){
console.log(res);
var data = JSON.parse(res.data) //字符串转化为JSON
//console.log(data);return;
if (data.Success == true){
//console.log(data);
var filename = urlStr + data.savename;
upload_picture_list[j]['path_server'] = filename;
}
that.setData({
upload_picture_list: upload_picture_list
})
console.log("图片上传" + j + "到服务器完成:")
console.log(upload_picture_list[j])
}
})
upload_task.onProgressUpdate((res) => {
//console.log('上传进度', res.progress)
//console.log('已经上传的数据长度', res.totalBytesSent)
//console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
upload_picture_list[j]['upload_percent'] = res.progress;
console.log('第' + j + '个图片上传进度:' + upload_picture_list[j]['upload_percent'])
console.log(upload_picture_list)
that.setData({
upload_picture_list: upload_picture_list
})
})
}
module.exports.upload_file_server = upload_file_server; //这样暴露接口,这里不暴露是不能引用的



php
<?php $filename = 'file'; $imgname = $_FILES[$filename]['name']; $tmp = $_FILES[$filename]['tmp_name']; $filepath = '/uploads/test/'; $data['Success'] = false; $data['savename'] = ''; $allowtype = array('png', 'gif', 'jpg', 'jpeg'); //var_dump($imgname); $arr = explode(".",$imgname); $hz = $arr[count($arr)-1]; $randname = date("YmdHis").rand(100, 999).".".$hz; if(move_uploaded_file($tmp,'.'.$filepath.$randname)){ #echo $filepath.$imgname; $data['Success'] = true; $data['savename'] = $filepath.$randname; }else{ #echo "上传失败"; $data['Success'] = false; $data['savename'] = ''; } echo json_encode($data);

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【php】excel导出分sheet

Continue Read..
    /**
     * 导出export 生成多个sheet
     * $data = [
     *      'sheet1'=>[
     *          'header'=>['k'=>v],
     *          'date'=>['k'=>v],
     *      ]
     *      'sheet2'=>[
     *          'header'=>['k'=>v]
     *          'data'=>['k'=>v]
     *      ]
     * ]
     * header和data 用k 关联
     * @param unknown $data
     * @param string $user
     * @param string $format
     * @param string $title
     * @return multitype:mixed
     */  
    public function multiExportSheet($data, $user = 'admin', $format = false, $title = ''){
        require_once __DIR__.'/PHPExcel.php';
        $objPHPExcel = new \PHPExcel();
        $j = 0;
        foreach ($data as $dk=>$dv){
            if($j==0){
                $objPHPExcel->setActiveSheetIndex($j); //设置第一个工作表为活动工作表
                $objPHPExcel->getActiveSheet()->setTitle($dk); //设置工作表名称
            }else{
                $msgWorkSheet = new \PHPExcel_Worksheet($objPHPExcel, $dk); //创建一个工作表
                $objPHPExcel->addSheet($msgWorkSheet); //插入工作表
                $objPHPExcel->setActiveSheetIndex($j); //切换到新创建的工作表
            }
            
            $arrHeader = $dv['header'];
            $arrBody = $dv['data'];
            $newdata = [];
            
            $i = 0;
            foreach ($arrBody as $k=>$v){
                foreach ($arrHeader as $kk=>$vv){
                    if(!empty($v[$kk])){
                        if($kk == 'idcard' || $kk == 'bank_card'){
                            $newdata[$i][$kk] = $v[$kk]."\t";
                        }else{
                            $newdata[$i][$kk] = $v[$kk];
                        }
                    }else{
                        $newdata[$i][$kk] = "";
                    }
                }
                $i++;
            }
            $hd[0] = $arrHeader;
            $arrExcelInfo = array_merge($hd, $newdata);
            $objPHPExcel->getActiveSheet()->fromArray(
                $arrExcelInfo, // 赋值的数组
                NULL, // 忽略的值,不会在excel中显示
                'A1' // 赋值的起始位置
            );
            
            unset($arrExcelInfo);
            unset($hd);
            unset($arrHeader);
            unset($arrBody);
            unset($newdata);
            $j++;
        }
        
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    
        $result=[];
        $path = 'down/'.md5($user.'down').'/';
        $rootPath = $this->mkdirPath($path);
        $date = date('YmdHis');
    
        $title = $date.rand(10000,99999);
        $outputFileName = $rootPath.$title.".xlsx";
        $objWriter->save($outputFileName);
        $result[]= str_replace(APP_PATH, '', $outputFileName);
        return $result;
    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【linux】gitlab和nginx冲突的解决方案

Continue Read..

vim /etc/gitlab/gitlab.rb

external_url = 'http://IP或域名'

unicorn['listen'] = '127.0.0.1'

unicorn['port'] = 3002

nginx['listen_addresses'] = ['*']

nginx['listen_port'] = 3001


如果修改了 external_url 

需修改/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml中 host 和 port

 

vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
listen "127.0.0.1:3002", :tcp_nopush => true



vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
listen *:3001;




改完之后
先关闭gitlab的ngxin服务
gitlab-ctl stop nginx

然后开启自己的nginx服务
service nginx start

然后启动gitlab的nginx服务
gitlab-ctl start nginx


gitlab的访问地址就是 http://127.0.0.1:3001/users/sign_in

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

vue.js 组件中filter后的数据,实时更新

Continue Read..

组件中的数据在模板显示后,变动数据发现不能更新的情况,可以做下面的检查

1、组件标签属性需要动态绑定v-bind:key="val"

2、VUE中加一个动态改变的变量time,动态绑定到组件标签对,props到组件中,在其他地方更新time就可以了

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】七牛,php<=5.3版本

Continue Read..
<?php
class SDK implements ArrayAccess {

	const QINIU_UP_HOST	= 'http://up.qiniu.com';
	const QINIU_RS_HOST	= 'http://rs.qbox.me';
	const QINIU_RSF_HOST= 'http://rsf.qbox.me';
	//查看 
	//删除 
	//复制 x
	//移动 x
	//上传 
	protected $access_token ;
	protected $secret_token ;
	protected $bucket;
	protected $cache = array();
	protected $aliases = array(); //文件别名, 针对文件名比较长的文件
	//curl 
	protected $ch;
	protected $headers;
	protected $options = array();
	protected $response;
	protected $info;
	protected $errno; 
	protected $error;

	public function __construct($access_token, $secret_token, $bucket = null)
	{
		$this->access_token = $access_token;
		$this->secret_token = $secret_token;
		$this->bucket = $bucket;
	}

	//获取空间名称
	public function getBucket()
	{
		return $this->bucket;
	}

	//设置空间
	public function setBucket($bucket)
	{
		$this->bucket = $bucket;
	}

	/**
	 * 查看指定文件信息。
	 * @param  string $key  	文件名或者目录+文件名
	 * @return Array|boolean 	成功返回文件内容,否会返回false.
	 */
	public function stat($key)
	{
		list($bucket, $key) = $this->parseKey($key);
		if ( is_null($bucket) ) 
		{
			die('error');
		}
		$url = self::QINIU_RS_HOST .'/stat/' . $this->encode("$bucket:$key");
		$token = $this->accessToken($url);
		$options[CURLOPT_HTTPHEADER] = array('Authorization: QBox '. $token);
		return $this->get($url, $options);
	}

	/**
	 * 删除指定文件信息。
	 * @param  string $key  	文件名或者目录+文件名
	 * @return NULL
	 */
	public function delete($key)
	{
		list($bucket, $key) = $this->parseKey($key);
		if ( is_null($bucket) ) 
		{
			die('error');
		}
		$url = self::QINIU_RS_HOST .'/delete/' . $this->encode("$bucket:$key");

		$token = $this->accessToken($url);
		$options[CURLOPT_HTTPHEADER] = array('Authorization: QBox '. $token);
		return $this->get($url, $options);
	}

	public function upload($file, $name=null, $token = null)
	{
		if ( NULL === $token ) 
		{
			$token = $this->uploadToken($this->bucket);
		}

		if ( !file_exists($file) ) 
		{
			die('文件不存在,构建一个临时文件');
		}
		$hash = hash_file('crc32b', $file);
		$array = unpack('N', pack('H*', $hash));
		$postFields = array(
			'token' => $token,
			'file'  => '@'.$file,
			'key'   => $name,
// 			'crc32' => sprintf('%u', $array[1]),
		);

		//未指定文件名,使用七牛默认的随机文件名
		if ( NULL === $name ) 
		{
			unset($postFields['key']);
		}
		else
		{
			//设置文件名后缀。
		}
		$options = array(
			CURLOPT_POSTFIELDS => $postFields,
		);
		return $this->get(self::QINIU_UP_HOST, $options);
	}

	protected function parseKey($key)
	{
		$key = $this->getAlias($key);
		if ( isset($this->cache[$key]) ) 
		{
			return $this->cache[$key];
		}
		$segments = explode("|", $key);
		if ( count($segments) === 1 ) 
		{
			$this->cache[$key] = array($this->bucket, $segments[0]);
		}
		else
		{
			$temp = implode('|', array_slice($segments, 1));
			$this->cache[$key] = array($segments[0], $temp);
		}
		return $this->cache[$key];
	}

	public function getAlias($key)
	{
		return isset($this->aliases[$key]) ? $this->aliases[$key] : $key;
	}

	public function uploadToken($config = array())
	{
		if ( is_string($config) ) 
		{
			$scope = $config;
			$config = array();
		}
		else
		{
			$scope = $config['scope'];
		}
		$config['scope'] = $scope;
		//硬编码,需修改。
		$config['deadline'] = time() + 3600;
		foreach ( $this->activeUploadSettings($config) as $key => $value ) 
		{
			if ( $value ) 
			{
				$config[$key] = $value;
			}
		}

		//build token
		$body = json_encode($config);
		$body = $this->encode($body);
		$sign = hash_hmac('sha1', $body, $this->secret_token, true);
		return $this->access_token . ':' . $this->encode($sign) . ':' .$body;
	}

	public function uploadSettings()
	{
		return array(
			'scope','deadline','callbackUrl', 'callbackBody', 'returnUrl',
			'returnBody', 'asyncOps', 'endUser', 'exclusive', 'detectMime',
			'fsizeLimit', 'saveKey', 'persistentOps', 'persistentNotifyUrl'
		);
	}

	protected function activeUploadSettings($array)
	{
		return array_intersect_key($array, array_flip($this->uploadSettings()));
	}

	public function accessToken($url, $body = false)
	{
		$url = parse_url($url);
		$result = '';
		if (isset($url['path'])) {
			$result = $url['path'];
		}
		if (isset($url['query'])) {
			$result .= '?' . $url['query'];
		}
		$result .= "\n";
		if ($body) {
			$result .= $body;
		}
		$sign = hash_hmac('sha1', $result, $this->secret_token, true);
		return $this->access_token . ':' . $this->encode($sign);
	}

	public function get($url, $options = array())
	{
		$this->ch = curl_init();
		$this->options[CURLOPT_URL] = $url;
		$this->options = $options + $this->options;
		//临时处理逻辑
		
		return $this->execute();
	}

	protected function execute() 
	{
		if ( !$this->option(CURLOPT_RETURNTRANSFER) ) 
		{
			$this->option(CURLOPT_RETURNTRANSFER, true);
		}
		if ( !$this->option(CURLOPT_SSL_VERIFYPEER) ) 
		{
			$this->option(CURLOPT_SSL_VERIFYPEER, false);
		}
		if ( !$this->option(CURLOPT_SSL_VERIFYHOST) ) 
		{
			$this->option(CURLOPT_SSL_VERIFYHOST, false);
		}
		if ( !$this->option(CURLOPT_CUSTOMREQUEST) ) 
		{
			$this->option(CURLOPT_CUSTOMREQUEST, 'POST');
		}
		if ( $this->headers ) 
		{
			$this->option(CURLOPT_HTTPHEADER, $this->headers);
		}
		$this->setupCurlOptions();

		$this->response = curl_exec($this->ch);
		$this->info = curl_getinfo($this->ch);

		if ( $this->response === false ) 
		{
			$this->error = curl_error($this->ch);
			$this->errno = curl_errno($this->ch);
			curl_close($this->ch);
			return false;
		}
		else
		{
			curl_close($this->ch);
			//未处理http_code。
			if ( $this->info['content_type'] == 'application/json' ) 
			{
				$this->response = json_decode($this->response, true);
			}
			return $this->response;
		}
	}
	public function setupCurlOptions()
	{
		curl_setopt_array($this->ch, $this->options);
	}

	public function option($key, $value = NULL)
	{
		if ( is_null($value) ) 
		{
			return !isset($this->options[$key]) ? null: $this->options[$key];
		}
		else
		{
			$this->options[$key] = $value;
			return $this;
		}
	}

	public function alias($key, $value)
	{
		$this->alias[$key] = $value;
	}

	protected function encode($str)
	{
        $trans = array("+" => "-", "/" => "_");
        return strtr(base64_encode($str), $trans);
	}

	public function __get($key)
	{
		return $this->$key;
	}

	public function offsetExists($key)
	{
		//check response;
	}

	public function offsetGet($key)
	{
		return $this->stat($key);
	}

	public function offsetSet($key, $value) 
	{
		//move or copy
	}

	public function offsetUnset($key)
	{
		return $this->delete();
	}
}


upload($filePath,$key);
var_dump($update);die;










声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

vue.js filter处理后返回显示html

Continue Read..
类似这样的代码
{{ description | filterfunction }}


filterfunction 返回一段html,
显示代码类似
<div v-html="description|filterfunction"


这样是不行的,应该这样

<div v-html="$options.filters.filterfunction(description)">


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】无限极函数

Continue Read..

数据库

CREATE TABLE `position` (
   `position_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '岗位id',
   `position_ids` text COMMENT '所属父级ids',
   `position_name` varchar(50) NOT NULL COMMENT '岗位名称',
   `position_addtime` int(11) DEFAULT NULL COMMENT '添加时间',
   `position_uptime` int(11) DEFAULT NULL COMMENT '修改时间',
   `parent_id` int(11) DEFAULT NULL COMMENT '父级id',
   `is_delete` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除',
   `role_id` int(10) DEFAULT NULL COMMENT '角色id',
   PRIMARY KEY (`position_id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COMMENT='岗位表'

点击查看原图

 

 

$data = select * from position

 

$newData = [];

foreach ($data as $k=>$v){

    $newData[$v['position_id']] = $v;

}

 

foreach ($data as $k=>$v){

    if($v['parent_id'] && isset($newData[$v['parent_id']])){

        $newData[$v['parent_id']]['son'][] = &$newData[$v['position_id']];

    }

}

 

var_dump($newData);die;

 

 

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

php crontab唯一实例运行

Continue Read..
#检测是否是唯一运行
if(!checkSingleRun($_SERVER['SCRIPT_FILENAME']))
{
	echo "{$_SERVER['SCRIPT_FILENAME']} is runnging....\n";
	exit;
}

#检测是否存在相同的进程正在运行,仅支持在linux下运行,windows下无法检测
function checkSingleRun($cronName,$limit=1,$isDebug=false)
{
	$flagIsRunning = true;
	$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != 'WIN';
	if($osIsLinux)
	{
		$arrayOutput = array();
		exec('ps -fea | grep ' . $cronName . ' | grep -v grep', $arrayOutput);
		$counter = 0;
		#调试模式时打印出匹配的进程信息
		if($isDebug)
			print_r($arrayOutput);

		$cronName_preg = str_replace('/','\/',$cronName);
		foreach ($arrayOutput as $value) 
		{
			if (preg_match('/^.*\s' . $cronName_preg . '.*$/', $value) 
					|| preg_match('/^.*\s.+(?:\x2F|\x5C)' . $cronName_preg . '.*$/', $value) ) 
			{
				$counter++;
			}
		}
		if ($counter > $limit) {
			$flagIsRunning = false;
		}
	}
	return $flagIsRunning;
}


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】php 操作LDAP

Continue Read..

1.首先安装php ldap的扩展

      参考网站http://blog.csdn.net/secondjanuary/article/details/8979686

  • 安装PHP的LDAP扩展
    • Windows下
      1. 如果你的php已经有php_ldap.dll文件,你可以打开php.ini文件, 找到 “;extension=php_ldap.dll” 去掉分号后保存
      2. 如果你没有php_ldap.dll文件,你可以从网上找的符合自己php版本的php_ldap.dll 文件,将文件放在相应的目录,重复上过程
      3. 重启Apache服务
    • Linux下
      1. 如果你的php是编译安装的,那么你需要加“--with-ldap”参数,重新编译安装
      2. 如果你的php是通过Linux的包管理器安装的,你可以通过包管理器安装php_ldap。 以Debian为例,执行apt-get install php5_ldap
      3. 重启Apache服务
  • 查看LDAP扩展是否安装成功
    • 打开phpinfo()测试画面,查看如下画面即php的ldap扩展方法启用成功:



        linux下扩展LDAP  

        参考网站 :http://www.sijitao.net/1851.html    https://my.oschina.net/kisshua/blog/199020




2. 编写代码测试

<?php

//phpinfo();  
$hostname="10.69.40.200";  
// $username = "cn=root,dc=www,dc=wulinlw,dc=org"; // Linux下管理员用户名的格式  
$username = "账号"; // Windows下管理员用户名的格式  
$password = "密码";  
$basedn = "dc=wulinlw,dc=org";  
$ds=ldap_connect($hostname,9999);  
if( $ds )  
{  
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION,3);  
        ldap_set_option($ds, LDAP_OPT_REFERRALS,0);  
          
        $r=ldap_bind($ds,$username,$password);  
        if($r){
    //         var_dump(ldap_error($ds));
            $filter   = "(|(objectClass=u*)(name=TONGXING))";
    //         $filter   = "(name=TONGXING)";
    //         $attr     =  array("displayName","description","cn","givenName","sn","mail","co","mobile","company","displayName");
            $attr     = array();
            $sr=ldap_search($ds, $basedn,$filter,$attr)or die ("Error in search query: ".ldap_error($ds));;  
    //         echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "
";
            
            $info = ldap_get_entries($ds, $sr);    
            echo json_encode($info);  
            //file_put_contents("D:\\json.json",json_encode($info));  
            var_dump($info['count']);  
            var_dump($info);  
            
        }
        ldap_close($ds);  
}   
else   
{  
    echo "

Unable to connect to LDAP server

"; } 


参考网站     

http://php.net/manual/zh/book.ldap.php     

http://jingyan.baidu.com/article/c85b7a642b2ee9003bac95b1.html

http://blog.itpub.net/750220/viewspace-878964/

http://www.cnblogs.com/qiuxiangmuyu/p/6437937.html

http://xuqq999.blog.51cto.com/3357083/786708

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

时间比较,判断:当天/昨天/昨天以前/隔年

Continue Read..
<script type="text/javascript">
var vd = new Date('2016/05/01 08:26:23');
var vy= vd.getFullYear();
var vm=vd.getMonth()+1;
var vda=vd.getDate();
var vh= vd.getHours();
var vmi= vd.getMinutes()

var d = new Date();
var cy=d.getFullYear();
var cm=d.getMonth() +1;
var cd=d.getDate();

if(vy==cy){
   var monthFlag = cm== vm? 1 : 0;
   var dateFlag = cd- vda;
   document.write(monthFlag+'--'+dateFlag+'>');
   if (monthFlag == 1 && dateFlag == 0) {
        document.write('今天');
   } else if (monthFlag == 1 && dateFlag == 1) {
        document.write('昨天');
   } else {
        document.write('昨天以前');
   }
}else{
   document.write('隔年');
}

</script>

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权