同一个网页如何放置多个Ueditor?
参考代码如下:
<form method="post" action="save.php">
<script type="text/plain" id="ueditorId_1" name="ueditorName_1" style="width: 400px;height:500px;">编辑器的默认值_1</script>
<script type="text/javascript">
UE.getEditor('ueditorId_1');
</script>
<script type="text/plain" id="ueditorId_2" name="ueditorName_2" style="width: 450px;height:550px;">编辑器的默认值_2</script>
<script type="text/javascript">
UE.getEditor('ueditorId_2');
</script>
</form>
这样,就会在页面中渲染2个Ueditor编辑器。
PHP如何获取多个Ueditor的值?
注意,上面的 ueditorName_1,ueditorName_2 即为表单的Name值,所以服务端PHP获取Ueditor编辑器的值变得很简单,参考代码如下:
$_POST["ueditorName_1"]; // 第一个编辑器的值
$_POST["ueditorName_2"]; // 第二个编辑器的值
解决百度 ueditor v1.4.3 编辑器上传图片失真的bug?
项目中,用到百度ueditor编辑器,发现,上传大一点的图片,图片会失真,刚开始还以为是PHP端做了图片压缩,仔细看配置说明,发现是编辑器自带有个自动压缩图片的功能,可恶的是,压缩后的图片失真了!
决定去掉这个压缩功能,如果非得要压缩,那就交给服务端PHP来处理吧!
找到配置文件:ueditor/php/config.json
把 imageCompressEnable 设置为 false 即可!
【总结】有2个比较重要的配置文件:
ueditor/ueditor.config.js
ueditor/php/config.json
解决file_get_contents遇到中文文件名无法打开问题
比如:受访页面_20151202-20151202.csv
file_get_contents(受访页面_20151202-20151202.csv)就会报错
[function.file-get-contents]: failed to open stream: No such file or directory
改成不用包含中文的文件名路径就可以。
原因:
编码问题,Windows中是使用gbk中文编码的,而PHP文件一般都是用utf-8格式保存的了。中文地址获取之前做一次iconv('utf-8', 'gbk', $path)就没有问题了。
<?php
$path='/baidu/受访页面_20151203-20151203.csv';
$path=iconv('utf-8', 'gbk', $path);
$content= file_get_contents($path);
echo $content;
?>
最初的做法
代码如下 | 复制代码 |
include 'classes/PHPExcel/IOFactory.php'; $inputFileName = $target;
$objPHPExcel = $objReader->load($inputFileName); |
报错
PHPExcel_Reader_Exception: The filename .1443578799.xlsx is not recognised as an OLE file in Classes\PHPExcel\Shared\OLERead.php on line 89
( ! ) Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'The filename 1443578799.xlsx is not recognised as an OLE file' in Classes\PHPExcel\Shared\OLERead.php on line 89
( ! ) PHPExcel_Reader_Exception: The filename 1443578799.xlsx is not recognised as an OLE file in Classes\PHPExcel\Shared\OLERead.php on line 89
Call Stack
碰到这个问题我们是因为xlsx出错了,可能通过类型判断 解决办法如下
代码如下 | 复制代码 |
if( $extension =='xlsx' ) |
这样再操作会发现问题已经解决了。
PHPMyAdmin编辑数据库表一直提示”正在加载”问题要如何来解决呢,碰到这种问题我们可以通过下面的方法来解决了,具体的操作步骤如下图所示。
代码如下 | 复制代码 |
# 查找
return strftime($date, $timestamp); # 替换成如下代码:
if(extension_loaded('gettext')) return strftime($date, $timestamp); # 中国区这样设置.
date_default_timezone_set('UTC'); return gmdate('Y-m-d H:i:s', $timestamp + 28800); |
解决 办法一,file_put_contents 高并发与独占锁定
发现高并发访问时使用 file_put_contents 写入文件造成数据置空。
查看官方文档:
int file_put_contents ( string $filename , string $data [, int $flags [, resource $context ]] )
参数:
filename 要被写入数据的文件名。 data 要写入的数据。类型可以是 string,array 或者是 stream 资源(如上面所说的那样)。 flags flags 可以是 FILE_USE_INCLUDE_PATH,FILE_APPEND 和/或 LOCK_EX(获得一个独占锁定),然而使用 FILE_USE_INCLUDE_PATH 时要特别谨慎。 context 一个 context 资源。
直接直至 flags 参数为 LOCK_EX 即可在高并发时获得一个独占锁定。
另外,flock 函数的也提供了文件锁定方法:
$fp = fopen("/tmp/lock.txt", "w+"); if (flock($fp, LOCK_EX)) { // 进行排它型锁定 fwrite($fp, "Write something here\n"); flock($fp, LOCK_UN); // 释放锁定 } else { echo "Couldn't lock the file !"; } fclose($fp);
注意 flock() 需要一个文件指针。
方法二,file_put_contents() 存在高并发问题,Smarty中处理方式如下。
<?php define("FILE_PUT_CONTENTS_ATOMIC_TEMP", dirname(__FILE__)."/cache"); define("FILE_PUT_CONTENTS_ATOMIC_MODE", 0777); function file_put_contents_atomic($filename, $content) { $temp = tempnam(FILE_PUT_CONTENTS_ATOMIC_TEMP, 'temp'); if (!($f = @fopen($temp, 'wb'))) { $temp = FILE_PUT_CONTENTS_ATOMIC_TEMP . DIRECTORY_SEPARATOR . uniqid('temp'); if (!($f = @fopen($temp, 'wb'))) { trigger_error("file_put_contents_atomic() : error writing temporary file '$temp'", E_USER_WARNING); return false; } } fwrite($f, $content); fclose($f); if ( !@rename($temp , $filename)) { @unlink($filename); @rename($temp, $filename); } @chmod($filename, FILE_PUT_CONTENTS_ATOMIC_MODE); return true; } ?>