作者:白羊蓝色雨线 | 来源:互联网 | 2018-05-12 13:01
第一步,以下代码扔到functions.phpfunctionget_qr($url,$path,$qrpic){set_time_limit(10);设置十秒超时$destination_folder$path?$path.:;$localname$destination_folder.$qrpic;$filefopen($url,rb);fopen函数的r+模式:读
第一步,以下代码扔到functions.php function get_qr($url,$path,$qrpic){ set_time_limit (10); //设置十秒超时$destination_folder = $path?$path.'/':''; $localname = $destination_folder .$qrpic; $file = fopen ($url, "rb"); //fopen函数的r+模式: 读
第一步,以下代码扔到functions.php
function get_qr($url,$path,$qrpic){
set_time_limit (10); //设置十秒超时
$destination_folder = $path?$path.'/':'';
$localname = $destination_folder .$qrpic;
$file = fopen ($url, "rb"); //fopen函数的r+模式: 读写方式打开 文件指针指向文件头
if ($file) {
$newf = fopen ($localname, "wb"); // w+,读写方式打开 文件指针指向文件头 如果文件不存在则尝试创建之
if ($newf)
while(!feof($file)) {
fwrite( $newf, fread($file, 1024 * 2 ), 1024 * 2 ); //写入文件,fread控制文件最大的大小,这里是2M
}
}
if ($file) {
fclose($file); //关闭fopen打开的文件
}
if ($newf) {
fclose($newf);
}
}
第二步,在网站根目录建立一个叫qrcode的新文件夹,确保有写入权限,
第三步,以下代码放到需要输出二维码图片的地方,如single.php
教程已经结束了,下面是写这段代码过程中我的一些感想,
- 关于PHP的
fopen
函数
fopen不能直接获取https打头的url
- 关于wordpress的
the_permalink
和get_permalink
函数
前者是display直接输出结果,后者是return返回值,在自定义函数中使用此类变量需要使用后者
例如the_id和get_the_id用法也是如此
fopen-qr is coded by xiaohudie. Any posts here is one hundred percent original, so please keep my link so as not to hurt this pretty girl