当前位置: 编程技术>php
本页文章导读:
▪apache+codeigniter 通过.htcaccess做动态二级域名解析
代码如下: AuthName "yousite Website Coming Soon..." //如果你想给你的网站加个权限访问 AuthType Basic AuthUserFile D:/xxx/.htpasswd #如果你想设置密码访问 如何生成.htpasswd可以访问 http://www.htaccesstools.com/htpas.........
▪php下载文件的代码示例
代码如下: <?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Cont.........
▪PHP sprintf() 函数的应用(定义和用法)
语法sprintf(format,arg1,arg2,arg++)
参数
描述
format
必需。转换格式。
arg1
必需。规定插到 format 字符串中第一个 % 符号处的参数。
arg2
可选。规定插到 format 字符串中第二个 % 符号处的参数。
.........
[1]apache+codeigniter 通过.htcaccess做动态二级域名解析
来源: 互联网 发布时间: 2013-11-30
代码如下:
AuthName "yousite Website Coming Soon..." //如果你想给你的网站加个权限访问
AuthType Basic
AuthUserFile D:/xxx/.htpasswd #如果你想设置密码访问 如何生成.htpasswd可以访问 http://www.htaccesstools.com/htpasswd-generator/
#AuthGroupFile /dev/null
require valid-user
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
<IfModule mod_proxy.c>
# Redirect to boutique (with any trailing path)
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).yousite.com(.*)$ [NC]
RewriteRule ^(.*)$ http://www.yousite.com/boutique/$1$2 [P,L]
</IfModule>
<IfModule !mod_proxy.c>
# Redirect to boutique (with any trailing path)
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).yousite.com(.*)$ [NC]
RewriteRule ^(.*)$ http://www.yousite.com/boutique/%1/$1 [R=301,L]
</IfModule>
## Otherwise, force www;
RewriteCond %{HTTP_HOST} ^yousite.com$ [NC]
RewriteRule ^(.*)$ http://www.yousite.com/$1 [R=301,L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
出处:cnblogs 微博:@草根小胡
[2]php下载文件的代码示例
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
以上代码是下载代码
接下来贴一段在线预览pdf文件的代码
代码如下:
<?php
public function fddAction()
{
// get attachment location
$attachment_location = $_SERVER["DOCUMENT_ROOT"] . "/pdf/fdd/sample.pdf";
if (file_exists($attachment_location)) {
// attachment exists
// send open pdf dialog to user
header('Cache-Control: public'); // needed for i.e.
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="sample.pdf"');
readfile($attachment_location);
die(); // stop execution of further script because we are only outputting the pdf
} else {
die('Error: File not found.');
}
}
?>
[3]PHP sprintf() 函数的应用(定义和用法)
来源: 互联网 发布时间: 2013-11-30
语法
?
<?php
$str = "Hello";
$number = 123;
$txt = sprintf("%s world. Day number %u",$str,$number);
echo $txt;
?>
输出:
Hello world. Day number 123
例子 2
<?php
$number = 123;
$txt = sprintf("%f",$number);
echo $txt;
?>
输出:
123.000000
例子 3
<?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f<br />With no decimals: %1\$u",$number);
echo $txt;
?>
输出:
With 2 decimals: 123.00
With no decimals: 123
例子4
<?php
$ctype_primary = strtolower('application');
$ctype_secondary = strtolower('pdf');
$mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
echo $mimetype;
?>
输出:
application/pdf
sprintf(format,arg1,arg2,arg++)参数 描述 format 必需。转换格式。 arg1 必需。规定插到 format 字符串中第一个 % 符号处的参数。 arg2 可选。规定插到 format 字符串中第二个 % 符号处的参数。 arg++ 可选。规定插到 format 字符串中第三、四等等 % 符号处的参数。 说明
参数 format 是转换的格式,以百分比符号 ("%") 开始到转换字符结束。下面的可能的 format 值:
%% - 返回百分比符号
%b - 二进制数
%c - 依照 ASCII 值的字符
%d - 带符号十进制数
%e - 可续计数法(比如 1.5e+3)
%u - 无符号十进制数
%f - 浮点数(local settings aware)
%F - 浮点数(not local settings aware)
%o - 八进制数
%s - 字符串
%x - 十六进制数(小写字母)
%X - 十六进制数(大写字母)
arg1, arg2, ++ 等参数将插入到主字符串中的百分号 (%) 符号处。该函数是逐步执行的。在第一个 % 符号中,插入 arg1,在第二个 % 符号处,插入 arg2,依此类推
提示和注释
注释:如果 % 符号多于 arg 参数,则您必须使用占位符。占位符插到 % 符号后面,由数字和 "\$" 组成。请参见例子 3。
例子
例子 1
代码如下:
?
<?php
$str = "Hello";
$number = 123;
$txt = sprintf("%s world. Day number %u",$str,$number);
echo $txt;
?>
输出:
Hello world. Day number 123
例子 2
代码如下:
<?php
$number = 123;
$txt = sprintf("%f",$number);
echo $txt;
?>
输出:
123.000000
例子 3
代码如下:
<?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f<br />With no decimals: %1\$u",$number);
echo $txt;
?>
输出:
代码如下:
With 2 decimals: 123.00
With no decimals: 123
例子4
代码如下:
<?php
$ctype_primary = strtolower('application');
$ctype_secondary = strtolower('pdf');
$mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
echo $mimetype;
?>
输出:
代码如下:
application/pdf
最新技术文章: