PHP遇到的问题和记录
linux查看系统未被挂载的磁盘空间的方法
转载:https://www.cnblogs.com/cc66/p/9414718.html
PHP 针对fastadmin 追加图片域名
if (!function_exists('cdnurl')) {
/**
* 获取上传资源的CDN的地址
* @param string $url 资源相对地址
* @param boolean $domain 是否显示域名 或者直接传入域名
* @return string
*/
function cdnurl($url, $domain = false)
{
$regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
$cdnurl = \think\Config::get('upload.cdnurl');
$url = preg_match($regex, $url) || ($cdnurl && stripos($url, $cdnurl) === 0) ? $url : $cdnurl . $url;
if ($domain && !preg_match($regex, $url)) {
$domain = is_bool($domain) ? request()->domain() : $domain;
$url = $domain . $url;
}
return $url;
}
}
linux 查看端口
https://www.runoob.com/w3cnote/linux-check-port-usage.html
Linux 查看端口占用情况可以使用 lsof 和 netstat 命令。
lsof
lsof(list open files)是一个列出当前系统打开文件的工具。
lsof 查看端口占用语法格式:
lsof -i:端口号
netstat
netstat -tunlp 用于显示 tcp,udp 的端口和进程等相关情况。
netstat 查看端口占用语法格式:
centos8平台使用wkhtmltopdf实现html网页转pdf
一,wkhtmltopdf的用途
wkhtmltopdf可以直接把任何一个可以在浏览器中浏览的网页直接转换成一个pdf
二,下载和安装wkhtmltopdf
1,官网地址:
https://wkhtmltopdf.org/downloads.html
2,下载:
[root@blog source]# wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos8.x86_64.rpm
3,安装
[root@blog source]# rpm -ivh wkhtmltox-0.12.5-1.centos8.x86_64.rpm
error: Failed dependencies:`
xorg-x11-fonts-75dpi is needed by wkhtmltox-1:0.12.5-1.centos8.x86_64
xorg-x11-fonts-Type1 is needed by wkhtmltox-1:0.12.5-1.centos8.x86_64
报错了,先把有依赖的两个包安装好:
[root@blog source]# dnf install xorg-x11-fonts-75dpi
[root@blog source]# dnf install xorg-x11-fonts-Type1
再次安装就OK了
[root@blog source]# rpm -ivh wkhtmltox-0.12.5-1.centos8.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:wkhtmltox-1:0.12.5-1.centos8 ################################# [100%]
三,查看版本和帮助
1,查看版本
[root@blog source]# /usr/local/bin/wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)
2,查看帮助
[root@blog source]# /usr/local/bin/wkhtmltopdf --help
3,查看手册
[root@blog source]# man wkhtmltopdf
四,wkhtmltopdf的用法例子:
1,转本地页面
复制代码
[root@blog ~]# /usr/local/bin/wkhtmltopdf /home/sysop/work/jianli.html /home/webop/work/jianli.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
复制代码
2,转线上的页面:
[root@blog ~]# /usr/local/bin/wkhtmltopdf http://www.baidu.com /home/webop/work/baidu.pdf
HTML 转 PDF 之 wkhtmltopdf 工具简介
转载:https://www.jianshu.com/p/559c594678b6
linux 系统tar文件压缩打包命令
打包成tar.gz格式压缩包
# tar -zcvf renwolesshel.tar.gz /renwolesshel 解压tar.gz格式压缩包
# tar zxvf renwolesshel.tar.gz 打包成tar.bz2格式压缩包
# tar -jcvf renwolesshel.tar.bz2 /renwolesshel 解压tar.bz2格式的压缩包
# tar jxvf renwolesshel.tar.bz2 压缩成zip格式
# zip -q -r renwolesshel.zip renwolesshel/ 解压zip格式的压缩包
# unzip renwolesshel.zip
转载https://www.linuxprobe.com/linux-tar.html
fastadmin表格优化
通用搜索指表格上方的搜索,通用搜索的表单默认是隐藏的,如果需要默认显示,需要设置
searchFormVisible: true
,如果不需要通用搜索功能,可以设置
commonSearch: false
。如果想要控制字段列不参考搜索则可以设置字段列属性为
operate: false
即可。
转载https://ask.fastadmin.net/article/323.html
fastadmin api 请求参数获取
/**
* 获取当前请求的参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值
* @param string|array $filter 过滤方法
* @return mixed
*/
public function param($name = '', $default = null, $filter = '')
{
if (empty($this->mergeParam)) {
$method = $this->method(true);
// 自动获取请求变量
switch ($method) {
case 'POST':
$vars = $this->post(false);
break;
case 'PUT':
case 'DELETE':
case 'PATCH':
$vars = $this->put(false);
break;
default:
$vars = [];
}
// 当前请求参数和URL地址中的参数合并
$this->param = array_merge($this->param, $this->get(false), $vars, $this->route(false));
$this->mergeParam = true;
}
if (true === $name) {
// 获取包含文件上传信息的数组
$file = $this->file();
$data = is_array($file) ? array_merge($this->param, $file) : $this->param;
return $this->input($data, '', $default, $filter);
}
return $this->input($this->param, $name, $default, $filter);
}
tp5连接oracle
添加文件:
Oracle.php
<?php
namespace think\db\connector;
use PDO;
use think\db\Connection;
use think\Log;
/**
* Oracle数据库驱动
*/
class Oracle extends Connection
{
protected $builder = '\\think\\oracle\\Builder';
/**
* 解析pdo连接的dsn信息
* @access protected
* @param array $config 连接信息
* @return string
*/
protected function parseDsn($config)
{
$dsn = 'oci:dbname=';
if (!empty($config['hostname'])) {
// Oracle Instant Client
// $dsn .= '//' . $config['hostname'] . ($config['hostport'] ? ':' . $config['hostport'] : '') . '/';
$dsn .= '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST='.$config['hostname'] .')(PORT='.$config['hostport'].'))(CONNECT_DATA=(SID='. $config['database'].')))';
}
//$dsn .= $config['database'];
if (!empty($config['charset'])) {
$dsn .= ';charset=' . $config['charset'];
}
return $dsn;
}
/**
* 取得数据表的字段信息
* @access public
* @param string $tableName
* @return array
*/
public function getFields($tableName)
{
$this->initConnect(true);
list($tableName) = explode(' ', $tableName);
$sql = "select a.column_name,data_type,DECODE (nullable, 'Y', 0, 1) notnull,data_default, DECODE (A .column_name,b.column_name,1,0) pk from all_tab_columns a,(select column_name from all_constraints c, all_cons_columns col where c.constraint_name = col.constraint_name and c.constraint_type = 'P' and c.table_name = '" . strtoupper($tableName) . "' ) b where table_name = '" . strtoupper($tableName) . "' and a.column_name = b.column_name (+)";
$pdo = $this->linkID->query($sql);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
if ($result) {
foreach ($result as $key => $val) {
$val = array_change_key_case($val);
$info[$val['column_name']] = [
'name' => $val['column_name'],
'type' => $val['data_type'],
'notnull' => $val['notnull'],
'default' => $val['data_default'],
'primary' => $val['pk'],
'autoinc' => $val['pk'],
];
}
}
return $this->fieldCase($info);
}
/**
* 取得数据库的表信息(暂时实现取得用户表信息)
* @access public
* @param string $dbName
* @return array
*/
public function getTables($dbName = '')
{
$pdo = $this->linkID->query("select table_name from all_tables");
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
foreach ($result as $key => $val) {
$info[$key] = current($val);
}
return $info;
}
/**
* 获取最近插入的ID
* @access public
* @param string $sequence 自增序列名
* @return string
*/
public function getLastInsID($sequence = null)
{
if ($sequence === null) {
return '';
}
$pdo = $this->linkID->query("select {$sequence}.currval as id from dual");
$result = $pdo->fetchColumn();
return $result;
}
/**
* SQL性能分析
* @access protected
* @param string $sql
* @return array
*/
protected function getExplain($sql)
{
return [];
}
protected function supportSavepoint()
{
return true;
}
}
D:\phpstudy_pro\WWW\oil\application\dataoracle.php
<?php
return [
// 数据库类型
'type' => 'oracle',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'ORCLt',
// 用户名
'username' => 'HR',
// 密码
'password' => 'test123',
// 端口
'hostport' => '1521',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '',
// 数据库调试模式
'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'array',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
];
在配置文件引入:
测试代码:
public function index()
{
$db = Db::connect('db_oracle');
halt($db);
$oracle_data = $db->query('SELECT "HR"."RV_PWEL_DAY_ALLOC".*,ROWID "NAVICAT_ROWID" FROM "HR"."RV_PWEL_DAY_ALLOC" OFFSET 0 ROWS FETCH NEXT 1000 ROWS ONLY');
halt($oracle_data);
$dbconn = oci_connect('system', 'test123', "(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = ORCLt)))");
if ($dbconn != false) {
} else {
echo "连接失败";
}
$sqle = 'SELECT "HR"."RV_PWEL_DAY_ALLOC".*,ROWID "NAVICAT_ROWID" FROM "HR"."RV_PWEL_DAY_ALLOC" OFFSET 0 ROWS FETCH NEXT 1000 ROWS ONLY';
$ora_testr = oci_parse($dbconn, $sqle); //编译sql语句
oci_execute($ora_testr, OCI_DEFAULT); //执行
$h = 0;
while ($r = oci_fetch_row($ora_testr)) //取回结果
{
echo $r[0];
}
}
apache 伪静态
<IfModule mod_headers.c>
Header always add Access-Control-Allow-Origin: "*"
Header always add Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,HEAD,OPTIONS"
Header always add Access-Control-Max-Age: "1000"
Header always add Access-Control-Allow-Credentials: "true"
Header always add Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept, token, platform"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
</IfModule>
nginx 伪静态
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { #允许静态资源跨域请求 add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, token, platform';
expires 30d; access_log off;
}
nginx重新加载配置
/nginx -t
/nginx -s reload