Submitted by gouki on 2015, October 20, 10:08 AM
position有9个点:lt,mt,rt,lm,mm,rm,lb,mb,rb,其实对应的是几个英文:lt(left top),mt(middle top),rt(right top),以此类推
上官方原图:

OK,然后我们看一下他的代码是怎么写的,如果有人涉及到也可以借鉴:
PHP代码
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static function calculatePositions($containerWidth, $containerHeight, $layerWidth, $layerHeight, $layerPositionX, $layerPositionY, $position = 'LT')
- {
- $position = strtolower($position);
-
- if ($position == 'rt') {
-
- $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
-
- } elseif ($position == 'lb') {
-
- $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
-
- } elseif ($position == 'rb') {
-
- $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
- $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
-
- } elseif ($position == 'mm') {
-
- $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
- $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
-
- } elseif ($position == 'mt') {
-
- $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
-
- } elseif ($position == 'mb') {
-
- $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
- $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
-
- } elseif ($position == 'lm') {
-
- $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
-
- } elseif ($position == 'rm') {
-
- $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
- $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
- }
-
- return array(
- 'x' => $layerPositionX,
- 'y' => $layerPositionY,
- );
- }
END;
Tags: imageworkshop, position
PHP | 评论:1
| 阅读:26724
Submitted by gouki on 2015, September 7, 10:56 PM
原文来自:http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains
主要是因为涉及到CSS和JS文件是挂在别的域,然后又遇到了ajax之类的操作,所以就需要有跨域操作了,本来很方便的,只是在.htaccess文件中加了一句
XML/HTML代码
- Header add Access-Control-Allow-Origin "http://xxxxxx.com"
但因为备案原因,所以又添加了一个备用域名,结果,就报错了,报错提示是:
XML/HTML代码
- font from origin 'http://xxxxx.com' has been blocked from loading by Cross-Origin Resource Sharing policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://yyyy.com, http://zzzz.com', but only one is allowed. Origin 'http://xxxxx.com' is therefore not allowed access.
我晶,不支持多域名啊,google了一下,找到了这一篇:http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains
不多贴,其实挺有意思。。方法也有不少
1、利用apache的环境变量:
XML/HTML代码
- SetEnvIf Origin "^(.*\.example\.com)$" ORIGIN_SUB_DOMAIN=$1
- <FilesMatch "\.woff$">
- Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN
- </FilesMatch>
2、用PHP来判断:
PHP代码
- $http_origin = $_SERVER['HTTP_ORIGIN'];
-
- if ($http_origin == "http://www.domain1.com" || $http_origin == "http://www.domain2.com" || $http_origin == "http://www.domain3.info")
- {
- header("Access-Control-Allow-Origin: $http_origin");
- }
3、和1有点类似
XML/HTML代码
- SetEnvIf Origin "^http(s)?://(.+\.)?(domain\.org|domain2\.com)$" origin_is=$0
- Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is
4、这是nginx的:
XML/HTML代码
- location /fonts {
- # this will echo back the origin header
- if ($http_origin ~ "example.org$") {
- add_header "Access-Control-Allow-Origin" $http_origin;
- }
- }
更多的,还是去原网页看吧。。
PHP | 评论:0
| 阅读:20948
Submitted by gouki on 2015, August 13, 5:16 PM
BUG提醒工具其实有很多,比如可以在有BUG的时候发封邮件到你的常用邮箱,这样你的手机上(邮件APP)就会收到一条提醒。或者有短信SP通道的话,你也可以有类似处理。当然还有monolog,支持php-console插件,可以发送到你的chrome上面,我在这里再换个小方式,利用pubu.im这个IM工具(或者说。。。。说不出来)来做提醒
流程很简单
1、去pubu.im测试一个帐户。。这不用我多说吧
2、下载MAC客户端登录,自己添加自己为一个机器人,相当于自己和自己聊天,如果你的消息不算隐私,你可以直接用现成的:小布 这个通道
3、在聊天界面选择插件,点击更多,打开网页,添加“incoming”插件,生成一个URL,选择你刚才聊天组
4、根据提示信息在你的APP里写上一段测试代码,POST方式的,可以用curl/file_get_contents/Requests/guzzle等,工具实在太多,不想多说
5、测试通过后,可以尝试自己用set_error_handle,自己处理出错信息,在出错信息前进行判断:
if(debug_mode){ //send report }
6、你会发现 右上角弹了一个小窗,就是你刚才的测试标题!
----EOF---
就这样,你在工作的时候不需要打开手机,电脑上会直接有提醒哦~~~而且因为是聊天记录,你还可以往前翻,到底是什么BUG,嗯,再也不用客户端开发人员和你说,XXX接口出错了。。。因为他一出错你就收到,然后你就可以在他没有和你提的时候悄悄的改掉,等他提出来有BUG的时候,你说,在哪里?一定是你访问的姿势不对,不信你试试
哈哈
Tags: bug
PHP | 评论:1
| 阅读:22048
Submitted by gouki on 2015, July 6, 3:39 PM
纯笔记做个记录
1、http://mirrors.aliyun.com/ ,这是阿里的源
2、这是dotdeb的说明:http://mirrors.aliyun.com/help/dotdeb
3、阿里云的说明:
XML/HTML代码
- 编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最后面添加以下条目(操作前请做好相应备份)
-
- deb http://mirrors.aliyun.com/dotdeb/packages.dotdeb.org wheezy all
- deb-src http://mirrors.aliyun.com/dotdeb/packages.dotdeb.org wheezy all
其实上面的源的写法是错误的,不需要package.dotdeb.org,应该是这样
XML/HTML代码
-
- deb http://mirrors.aliyun.com/dotdeb wheezy all
- deb-src http://mirrors.aliyun.com/dotdeb wheezy all
不过,如果是默认这样其实没有什么特别用,PHP还是5.4,所以如果要针对PHP,就需要再加上
XML/HTML代码
- deb http://mirrors.aliyun.com/dotdeb wheezy-php56 all
- deb-src http://mirrors.aliyun.com/dotdeb wheezy-php56 all
其实说白了就是看:http://mirrors.aliyun.com/dotdeb/dists/,看这一页支持哪些,然后加在源里就OK了。就象官网说的,如果是阿里云服务器,请使用aliyuncs,流量直接从内网走~
PHP | 评论:0
| 阅读:19603
Submitted by gouki on 2015, June 19, 9:13 AM
众所周知,用curl上传只要设置4个变量即可(非HTTPS网站),那就是curlopt_url,curlopt_post,curlopt_returntransfer,curlopt_postfields,当然这4个都是大写。
curlopt_post,curlopt_returntransfer 都是 true,curlopt_url则是你要提交的网址,那么剩下的,curlopt_postfields就是你要上传的内容了。
上传文件在这里也变得非常简单,只需对应的值前面加个“@”即可,如curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>'@/var/www/images/abc.jpg')); 文件通过realpath判断后存在的即可。
但是,这一切在php5.6里就发生了改成。php5.6不再支持@这样的上传方式,只能使用curl_file_create的方式来,所以上面的代码要改成
PHP代码
- curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>curl_file_create('/var/www/images/abc.jpg','image/jpg','abc')));
看看文档里怎么说:
XML/HTML代码
- CURLFile should be used to upload a file with CURLOPT_POSTFIELDS.
然后官网的手册中的最后一条评论,仿佛是看不下去,写了个处理上传的程序
PHP代码
- There are "@" issue on multipart POST requests.
-
- Solution for PHP 5.5 or later:
- - Enable CURLOPT_SAFE_UPLOAD.
- - Use CURLFile instead of "@".
-
- Solution for PHP 5.4 or earlier:
- - Build up multipart content body by youself.
- - Change "Content-Type" header by yourself.
-
- The following snippet will help you :D
-
- <?php
-
-
-
-
-
-
-
-
-
- function curl_custom_postfields($ch, array $assoc = array(), array $files = array()) {
-
-
- static $disallow = array("\0", "\"", "\r", "\n");
-
-
- foreach ($assoc as $k => $v) {
- $k = str_replace($disallow, "_", $k);
- $body[] = implode("\r\n", array(
- "Content-Disposition: form-data; name=\"{$k}\"",
- "",
- filter_var($v),
- ));
- }
-
-
- foreach ($files as $k => $v) {
- switch (true) {
- case false === $v = realpath(filter_var($v)):
- case !is_file($v):
- case !is_readable($v):
- continue;
- }
- $data = file_get_contents($v);
- $v = call_user_func("end", explode(DIRECTORY_SEPARATOR, $v));
- $k = str_replace($disallow, "_", $k);
- $v = str_replace($disallow, "_", $v);
- $body[] = implode("\r\n", array(
- "Content-Disposition: form-data; name=\"{$k}\"; filename=\"{$v}\"",
- "Content-Type: application/octet-stream",
- "",
- $data,
- ));
- }
-
-
- do {
- $boundary = "---------------------" . md5(mt_rand() . microtime());
- } while (preg_grep("/{$boundary}/", $body));
-
-
- array_walk($body, function (&$part) use ($boundary) {
- $part = "--{$boundary}\r\n{$part}";
- });
-
-
- $body[] = "--{$boundary}--";
- $body[] = "";
-
-
- return @curl_setopt_array($ch, array(
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => implode("\r\n", $body),
- CURLOPT_HTTPHEADER => array(
- "Expect: 100-continue",
- "Content-Type: multipart/form-data; boundary={$boundary}",
- ),
- ));
- }
好吧,其实多文件上传用这样的方式就挺好。
PHP | 评论:1
| 阅读:22569