今天一个二逼朋友让我帮忙写个股票查询的类,来集成到微信中,所以花了一点时间写了一个不完整的,哈哈,如果有想玩的人,可以继续提交代码,让它变得完善起来!!
GitHub 地址:github.com/widuu/stock
代码如下:
代码如下 | 复制代码 |
class stock{ /** const STOCK_URL = "http://apis.baidu.com/apistore/stockservice/stock"; const SOCKET_SUGGEST = "http://cjhq.baidu.com/suggest?code5="; /** private static $instance; /** private static $apikey; /** public static function getInstance($apikey){ return self::$instance; /** public static function getName($stockid){ /** public static function getTime($stockid){ /** public static function getKline($stockid,$date='min'){ /** public static function getSingleStock($stockid){ /** private static function getStockId($name){ /** private static function httpGet($url,$header=false) { //测试代码 |
今天其实想搭建个社区,专门为 Zephir/Phalcon/Yaf/Docker/Swoole 建设一个社区, 专门为 C 语言的PHP框架和 C 语言扩展做一个,刚开始挺高兴的,直接用 wecenter 搭建多好,而且官网说支持 SAE,我就信心满满的去了,结果不行,坑爹呀,新浪那么大字,mysql 不支持 host:port 没看吗? 稍微修改一下就可以了。
0x01
修改 system\Zend\Db\Adapter\Mysqli.php ,搜索找到 // Suppress connection warnings here. ,然后在上边加入以下代码:
代码如下 | 复制代码 |
//修复SAE上连接错误 BUG add by widuu 2015/4/23 if (defined('IN_SAE')){ $host = $this->_config['host']; $this->_config['host'] = strstr($host,':',true); $port = trim(strstr($host,':'),':'); } // end by widuu |
修改 system\Zend\Db\Adapter\Pdo\Abstract.php,搜索一下代码:
代码如下 | 复制代码 |
return $this->_pdoType . ':' . implode(';', $dsn); |
然后替换成如下这样:
代码如下 | 复制代码 |
//修复SAE上连接错误 BUG add by widuu 2015/4/23 |
伪静态不管用,大哥你知道吗,最好看看官方的 API,然后伪静态变成如下就可以了:
name: 你的应用名称
version: 你的版本
handle:
代码如下 | 复制代码 |
- rewrite: if (!-d && !-f) goto "/index.php?%{QUERY_STRING}" |
好就到这里,明天预告,更新 Phalcon 的东西,我也想更新 YAF 的知识,当然一个一个慢慢来。然后是 Zephir。
七牛图片上传方法我们只要在框架中配置它的接口及上传的些小细节就可以实现了,下面一起来看一个关于配置Thinkphp3.2支持七牛图片上传的方法,希望文章对各位有帮助。作为php菜鸟,在公司捣鼓的一个基于thinkphp框架项目上要是用七牛(原来有用过C#版本的sdk)。现在在官方找到php的官方sdk,最后发现原来Thinkphp已经支持驱动类型是qiniu的文件上传了。
现在将配置说明一下。
利用七牛云私有空间存储文件
注册七牛云,创建空间,将空间设为私有
需要记下的东西:
AK,SK,bucket
在config.php添加
//七牛上传文件设置
'PICTURE_UPLOAD_DRIVER'=>'Qiniu',
//本地上传文件驱动配置
'UPLOAD_LOCAL_CONFIG'=>array(),
'UPLOAD_QINIU_CONFIG'=>array(
'accessKey'=>'l3N4q0XCqm0rssaaMTHryZYG-LnKMH',
'secrectKey'=>'7qPVaeRasasan2TjALqQAjF0h6jOt0D1jF',
'bucket'=>'yaasasnbao',
'domain'=>'7xasssa.com2.z0.glb.qiniucdn.com',
'timeout'=>3600,
),
3、添加一个上传类Model
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------
namespace Admin\Model;
use Think\Model;
use Think\Upload;
/**
* 图片模型
* 负责图片的上传
*/
class PictureModel extends Model{
/**
* 自动完成
* @var array
*/
protected $_auto = array(
array('status', 1, self::MODEL_INSERT),
array('create_time', NOW_TIME, self::MODEL_INSERT),
);
/**
* 文件上传
* @param array $files 要上传的文件列表(通常是$_FILES数组)
* @param array $setting 文件上传配置
* @param string $driver 上传驱动名称
* @param array $config 上传驱动配置
* @return array 文件上传成功后的信息
*/
public function upload($files, $setting, $driver = 'Local', $config = null){
/* 上传文件 */
$Upload = new Upload($setting, $driver, $config);
$info = $Upload->upload($files);
if($info){ //文件上传成功,记录文件信息
return $info; //文件上传成功
} else {
$this->error = $Upload->getError();
return false;
}
}
/**
* 下载指定文件
* @param number $root 文件存储根目录
* @param integer $id 文件ID
* @param string $args 回调函数参数
* @return boolean false-下载失败,否则输出下载文件
*/
public function download($root, $id, $callback = null, $args = null){
/* 获取下载文件信息 */
$file = $this->find($id);
if(!$file){
$this->error = '不存在该文件!';
return false;
}
/* 下载文件 */
switch ($file['location']) {
case 0: //下载本地文件
$file['rootpath'] = $root;
return $this->downLocalFile($file, $callback, $args);
case 1: //TODO: 下载远程FTP文件
break;
default:
$this->error = '不支持的文件存储类型!';
return false;
}
}
/**
* 检测当前上传的文件是否已经存在
* @param array $file 文件上传数组
* @return boolean 文件信息, false - 不存在该文件
*/
public function isFile($file){
if(empty($file['md5'])){
throw new \Exception('缺少参数:md5');
}
/* 查找文件 */
$map = array('md5' => $file['md5'],'sha1'=>$file['sha1'],);
return $this->field(true)->where($map)->find();
}
/**
* 下载本地文件
* @param array $file 文件信息数组
* @param callable $callback 下载回调函数,一般用于增加下载次数
* @param string $args 回调函数参数
* @return boolean 下载失败返回false
*/
private function downLocalFile($file, $callback = null, $args = null){
if(is_file($file['rootpath'].$file['savepath'].$file['savename'])){
/* 调用回调函数新增下载数 */
is_callable($callback) && call_user_func($callback, $args);
/* 执行下载 */ //TODO: 大文件断点续传
header("Content-Description: File Transfer");
header('Content-type: ' . $file['type']);
header('Content-Length:' . $file['size']);
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
header('Content-Disposition: attachment; filename="' . rawurlencode($file['name']) . '"');
} else {
header('Content-Disposition: attachment; filename="' . $file['name'] . '"');
}
readfile($file['rootpath'].$file['savepath'].$file['savename']);
exit;
} else {
$this->error = '文件已被删除!';
return false;
}
}
/**
* 清除数据库存在但本地不存在的数据
* @param $data
*/
public function removeTrash($data){
//$this->where(array('id'=>$data['id'],))->delete();
}
}
4、修改调用上传类的代码
public function ImgUpload()
{
//$this->error("没有文件!");
//TODO: 用户登录检测
/* 调用文件上传组件上传文件 */
$Picture = D('Picture');
$pic_driver = C('PICTURE_UPLOAD_DRIVER');
$info = $Picture->upload(
$_FILES,
C('PICTURE_UPLOAD'),
C('PICTURE_UPLOAD_DRIVER'),
C("UPLOAD_{$pic_driver}_CONFIG")
); //TODO:上传到远程服务器
/* 记录图片信息 */
if($info){
/* 返回JSON数据 */
echo json_encode($info);
} else {
echo json_encode($info);
}
}
5、在客户端使用ajaxfileupload调用php方法
//上传图片
$(document).on('change','#upfile',function(){
$.ajaxFileUpload({
url:'{:U("Company/ImgUpload")}',
secureuri:false,
fileElementId:'upfile',
dataType: 'json',
type:'post',
data: { fileElementId: 'upfile'},
success: function (data) {
$('#showimg').attr('src',data.upfile.url);
$('#imageurl').val(data.upfile.url);
}
})
})
这里最好使用json的数据类型进行传输
文件夹文件拷贝/复制函数如下
/** * 文件夹文件拷贝 * * @param string $src 来源文件夹 * @param string $dst 目的地文件夹 * @return bool */ function dir_copy($src = '', $dst = '') { if (empty($src) || empty($dst)) { return false; } $dir = opendir($src); dir_mkdir($dst); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($src . '/' . $file)) { dir_copy($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); return true; } /** * 创建文件夹 * * @param string $path 文件夹路径 * @param int $mode 访问权限 * @param bool $recursive 是否递归创建 * @return bool */ function dir_mkdir($path = '', $mode = 0777, $recursive = true) { clearstatcache(); if (!is_dir($path)) { mkdir($path, $mode, $recursive); return chmod($path, $mode); } return true; }
PHP复制文件夹及下面所有文件,参考如下:
function xCopy($source, $destination, $child){ //用法: // xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录 // xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录 //参数说明: // $source:源目录名 // $destination:目的目录名 // $child:复制时,是不是包含的子目录 if(!is_dir($source)){ echo("Error:the $source is not a direction!"); return 0; } if(!is_dir($destination)){ mkdir($destination,0777); } $handle=dir($source); while($entry=$handle->read()) { if(($entry!=".")&&($entry!="..")){ if(is_dir($source."/".$entry)){ if($child) xCopy($source."/".$entry,$destination."/".$entry,$child); } else{ copy($source."/".$entry,$destination."/".$entry); } } } return 1; } ?>
我将使用Windows系统的设备定为PC,毕竟博客面向中国用户,大部分家用设备还是用的Windows系统
原理是判断浏览器提交的USER AGENT
代码如下 | 复制代码 |
<?php //分析数据 //输出数据 |
如果你只判断是否为iphone设备可以如下来进行操作
代码如下 | 复制代码 |
function get_device_type(){ |