2012年9月24日星期一

添加Notepad++到鼠标右键


添加系统右键菜单,就需要手动修改注册表了。

Windows Registry Editor Version 5.00 
[HKEY_CLASSES_ROOT\*\Shell\NotePad++] 
[HKEY_CLASSES_ROOT\*\Shell\NotePad++\Command] @="\"D:\\Program Files (x86)\\npp\\notepad++.exe\" \"%1\""

ssh公钥连接


产生公钥和私钥(在A上操作)
#cd ~/.ssh
#ssh-keygen -t rsa 然后一路回车,如果原来已经有公钥需要输入y来覆盖
copy公钥到B(在A上操作)
# scp -p ~/.ssh/id_rsa.pub sherry@B:~/.ssh/authorized_keys
私钥文件名:id_rsa
公钥文件名:id_rsa.pub

2012年9月3日星期一

WAMP环境配置https


cd /d D:\wamp\bin\apache\Apache2.2.11\bin
cp APACHE_CONF/openssl.cnf .
openssl
OpenSSL> req -new -x509 -days 999 -nodes -out apache.pem -keyout apache.pem -config openssl.cnf
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
....++++++
...++++++
writing new private key to 'apache.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:shanghai
Locality Name (eg, city) []:shanghai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:op
Organizational Unit Name (eg, section) []:op
Common Name (eg, YOUR name) []:Shore
Email Address []:sh@g.com
在httpd.conf中添加两行:

LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
修改httpd-ssl.conf:

修改其中一行(路径相应改变):

SSLCertificateFile "D:/wamp/bin/apache/Apache2.2.11/bin/apache.pem"
重启Apache,OKAY!

httpswamp

2012年6月27日星期三

php图片处理:尺寸|复制|合并|缩放|旋转|灰度|模糊处理

图片处理-php 

  1.获取图片尺寸 
  $filename = "img/photo.jpg"; 
  list($width, $height, $type, $attrib) = getimagesize($filename); 
  echo ""; 

  2.剪切图片复制内容到剪贴板 
  代码:
  //原始图像 
  $src_img = imageCreateFromPNG("big.png"); 
  //创建图像 
  $dst_img = imageCreateTrueColor(200, 200); 
  //剪切图像 
  imageCopy ($dst_img, $src_img, 0, 0, 50, 50, 200, 200); 
  //生成剪切后的图像 
  imagePNG($dst_img, "small.png"); 
  //销毁内存中的图像 
  imageDestroy($dst_img); 
  imageDestroy($src_img); 

  3.合并图片 
  //绘制椭圆形 
  $dst_img = imageCreateTrueColor (200, 200); 
  imageFilledRectangle($dst_img, 0, 0, 200, 200, 
  imageColorAllocate($dst_img, 255, 255, 255)); 
  $dst_blue = imageColorAllocate($dst_img, 0, 0, 255); 
  imageFilledEllipse($dst_img, 100, 100, 180, 140, $dst_blue); 
  //绘制三角形 
  $src_img = imageCreateTrueColor (200, 200); 
  imageFilledRectangle($src_img, 0, 0, 200, 200, 
  imageColorAllocate($src_img, 255, 255, 255)); 
  $src_red = imageColorAllocate($src_img, 255, 0, 0); 
  imageFilledPolygon($src_img, array(100, 20, 180, 180, 20, 180), 3, $src_red); 
  //图像的合并 
  imageCopyMerge($dst_img, $src_img, 0, 0, 0, 0, 200, 200, 75); 
  //生成PNG图片 
  header("Content-type: image/png"); 
  imagePNG($dst_img); 
  //消除内存图像 
  imageDestroy($dst_img); 
  imageDestroy($src_img); 

  4.缩放图像
  //指定的图像 
  $filename = 'photo.png'; 
  //获得图像的尺寸 
  list($width, $height) = getImageSize($filename); 
  //新图像的大小 
  $new_width = $width * 0.5; 
  $new_height = $height * 0.5; 
  //生成缩略图 
  $image_d = imageCreateTrueColor ($new_width, $new_height); 
  $image_s = imageCreatefromPNG ($filename); 
  imageCopyResampled ($image_d, $image_s, 0, 0, 0, 0, 
  $new_width, $new_height, $width, $height); 
  //输出JPEG图像 
  header ('Content-type: image/jpeg'); 
  imageJPEG($image_d, null, 99); //实现99%压缩 

  5.旋转图像
  //载入图片 
  $filename = 'photo.png'; 
  $image = imageCreateFromPNG($filename); 
  //旋转60度,没有覆盖到的地方使用白色 
  $rotate = imageRotate($image, 60, imageColorAllocate($image, 255, 255, 255)); 
  //输出图像 
  header('Content-type: image/jpeg'); 
  imageJPEG($rotate); 
  imageDestroy($rotate); 
  imageDestroy($image); 

  6.灰度处理 
  //打开图像 
  $im = imageCreateFromPNG('dave.png'); 
  if ($im && imageFilter($im, IMG_FILTER_GRAYSCALE)) 
  { 
  echo '灰度处理成功!'; 
  imagePNG($im, 'dave.png'); 
  } else { 
  echo '灰度处理失败!'; 
  } 
  //消除内存图像 
  imageDestroy($im); 

  7.模糊处理
  
  //打开图像 
  $im = imageCreateFromPNG('sean.png'); 
  if ($im && imageFilter($im, IMG_FILTER_GAUSSIAN_BLUR)) 
  { 
  echo '亮度改变成功!'; 
  imagePNG($im, 'sean.png'); 
  }else{ 
  echo '亮度改变失败!'; 
  }
  //消除内存图像 
  imageDestroy($im); 

2012年6月10日星期日

CURL模拟登录获取及提交数据的函数


  1. $cookie_file = dirname(__FILE__)."/cookie_".md5(basename(__FILE__)).".txt"// 设置Cookie文件保存路径及文件名   
  2.   
  3. function vlogin($url,$data){ // 模拟登录获取Cookie函数   
  4.     $curl = curl_init(); // 启动一个CURL会话   
  5.     curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址               
  6.     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查   
  7.     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在   
  8.     curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器   
  9.     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转   
  10.     curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer   
  11.     curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求   
  12.     curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包   
  13.     curl_setopt($curl, CURLOPT_COOKIEJAR, $GLOBALS['cookie_file']); // 存放Cookie信息的文件名称   
  14.     curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // 读取上面所储存的Cookie信息   
  15.     curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环   
  16.     curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容   
  17.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回   
  18.     $tmpInfo = curl_exec($curl); // 执行操作   
  19.     if (curl_errno($curl)) {   
  20.        echo 'Errno'.curl_error($curl);   
  21.     }   
  22.     curl_close($curl); // 关闭CURL会话   
  23.     return $tmpInfo// 返回数据   
  24. }   
  25.   
  26. function vget($url){ // 模拟获取内容函数   
  27.     $curl = curl_init(); // 启动一个CURL会话   
  28.     curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址               
  29.     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查   
  30.     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在   
  31.     curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器   
  32.     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转   
  33.     curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer   
  34.     curl_setopt($curl, CURLOPT_HTTPGET, 1); // 发送一个常规的Post请求   
  35.     curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // 读取上面所储存的Cookie信息   
  36.     curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环   
  37.     curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容   
  38.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回   
  39.     $tmpInfo = curl_exec($curl); // 执行操作   
  40.     if (curl_errno($curl)) {   
  41.        echo 'Errno'.curl_error($curl);   
  42.     }   
  43.     curl_close($curl); // 关闭CURL会话   
  44.     return $tmpInfo// 返回数据   
  45. }   
  46.   
  47. function vpost($url,$data){ // 模拟提交数据函数   
  48.     $curl = curl_init(); // 启动一个CURL会话   
  49.     curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址               
  50.     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查   
  51.     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在   
  52.     curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器   
  53.     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转   
  54.     curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer   
  55.     curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求   
  56.     curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包   
  57.     curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // 读取上面所储存的Cookie信息   
  58.     curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环   
  59.     curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容   
  60.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回   
  61.     $tmpInfo = curl_exec($curl); // 执行操作   
  62.     if (curl_errno($curl)) {   
  63.        echo 'Errno'.curl_error($curl);   
  64.     }   
  65.     curl_close($curl); // 关键CURL会话   
  66.     return $tmpInfo// 返回数据   
  67. }   
  68.   
  69. function delcookie($cookie_file){ // 删除Cookie函数   
  70.  @unlink($cookie_file); // 执行删除   
  71. }   
  72.   
  73. // 使用实例   
  74. if(!file_exists($cookie_file)) { // 检测Cookie是否存在   
  75. $str = vget('http://www.kalvin.cn/?action=login'); // 获取登录随机值   
  76. preg_match("/name=\"formhash\" value=\"(.*?)\"/is",$str,$hash); // 提取登录随机值   
  77. vlogin('http://www.kalvin.cn/post.php','action=dologin&formhash='.$hash[1].'&username=aaa&password=bbb&clientcode=ccc'); // 登录获取Cookie   
  78. }   
  79. echo vget('http://www.kalvin.cn/');   
  80. ?> 

2012年5月30日星期三

drupal用程序创建node的方法


01function createNode($data array(), $filepath = NULL) {
02    //private function,not necessary to read/copy
03    //the
04    $node new stdClass;
05    $node->type = "story";
06    $node->nid = 0;
07    $node->uid = 1;
08    $node->status = 1;
09    $node->promote = 1;
10    $node->changed = $node->created = time();
11    $node->sticky = 0;
12    $node->format=2;
13    $node->title = 'demo node';
14    $node->body = 'demo content';
15    //$node->taxonomy=array(1,2);
16     
17    foreach($data as $key => $val) {
18        $node->$key $val;
19    }
20     
21    if($filepath) {
22        $file=_ufileobj($filepath);
23        $filearray=_cck_filepre($file);
24        $node->field_image[0]= $filearray;   // 文件字段,手工改动
25    }
26    node_save($node);
27    $nid=$node->nid;
28    $node=NULL;
29    return $nid;
30}
31 
32function _ufileobj($filepath) {
33// Create a new file record --object
34//print_r(ufileobj( file_directory_path()."/test/test1.flv" ));
35    $file new stdClass();
36    //$file->fid=NULL;//when upload success , will return
37    $file->list = 1;
38    //data igore
39    $file->uid = $uid;
40    $file->filename = basename($filepath);
41    $file->filepath = $filepath;
42    $file->filemime = file_get_mimetype(basename($filepath));
43    $file->filesize filesize($filepath);
44    // You can change this to the UID you want
45     
46    $file->status = 1;
47    $file->timestamp = time();
48    $file->new = true;//addition field , seems useless
49     
50    drupal_write_record('files'$file);
51    // file_set_status($file,1);
52    //$node->files[$file_obj->fid] = $file_obj;
53    return $file;
54}
55 
56function _cck_filepre($file) {
57    //return file array which suits drupal cck file field
58    //$file is the result ofufileobj($filepath);
59    $filearray=array();
60    $filearray[fid]=$file->fid;
61    $filearray["list"]=1;
62    $filearray[data]=array("description"=>"","alt"=>"","title"=>"");
63    $filearray[uid]=1;
64    $filearray[filename]=$file->filename;
65    $filearray[filepath]=$file->filepath;
66    $filearray[filemime]=$file->filemime;
67    $filearray[filesize]=$file->filesize;
68    $filearray[status]=1;
69    $filearray[timestamp]=$file->timestamp;
70    return $filearray;
71}

上海松善实业有限公司

    上海松善实业有限公司是一家集多品牌销售于一体的电线电缆骨干企业,公司成立于2016年。 公司拥有国内各大品牌:起帆、远东、上上、江南、胜华等。     主要产品有:高低压电力电缆、橡套电缆、控制电缆、架空绝缘电缆、塑胶电缆、电子计算机电缆、通讯电缆、...