谁能解释一下这个路径http://localhost/index.php/admin/home
这种叫Pathinfo
我理解为是一种URL形式
用MVC来解读这个URL
home:控制器/方法
tp框架pathinfo格式怎么配置
我们在安装lnmp一键安装的时候,一般都没有开启访问pathinfo模式
这种模式在比较多的框架中用到,比如国人的ThinkPHP,还比如C写的Yaf也用到,不支持就比较可惜了。
pathinfo的原理就是将index.php/xxxx/xxx类似的网址当做php来执行,并且需要将xxx/xxx写入到$_SERVER中
这个是lnmp.org(我装的就是这个,所以我以这个为例子)开出来的虚拟机的配置中的一段(vhost/***.conf),修改nginx配置文件也是这样修改
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
大家明显看到,location中的正则中,写了一个$,悲剧了,表示就此结束(?表示前面的php只匹配一次,这个只是随便提提)
最终,应该如此处理(location哪里也修改了,因为我没有用到php5处理):
if (!-e $request_filename)
{
rewrite ^\/(.*)$ /index.php/$1 last;
break;
}
location ~ \.php
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
set $path_info ““;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$“) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
后面的部分处理我是参考的网络上搜索到的文档,带注释版告诉大家
location ~ \.php
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
set $path_info ““;#初始化一个变量
set $real_script_name $fastcgi_script_name;#初始化一个变量,并且获取到一个原始赋值
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$“) {#检测如果.php后面还存在/开始参数,将参数处理
set $real_script_name $1;#将第一个正则子串匹配到的赋值
set $path_info $2;#将第二个正则子串匹配到的赋值
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;#修改SCRIPT_FILENAME值
fastcgi_param SCRIPT_NAME $real_script_name;#修改SCRIPT_NAME值
fastcgi_param PATH_INFO $path_info;#修改PATH_INFO值
#上述三个赋值都是replace into的模式,这些值都是写在fcgi.conf中
}
wdcp nginx apache版本中怎么配置pathinfo模式
nginx模式默认是不支持pathinfo模式的,类似index.php/index形式的url会被提示找不到页面。下面的通过正则找出实际文件路径和pathinfo部分的方法,让nginx支持pathinfo。
假如要让 www.linuxeye.com站点支持pathinfo,具体配置如下:
server {
listen 80;
server_name www.linuxeye.com;
access_log logs/www.linuxeye.com.log combined;
root /home/wwwroot/www.linuxeye.com;
error_page 404 /404.html;
index index.html index.htm index.php ;
location / {
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi_pathinfo.conf;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$“) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
要点:
1.~ \.php 后面不能有$ 以便能匹配所有 *.php/* 形式的url
2. 通过设置更改 SCRIPT_FILENAME
cat fcgi_pathinfo.conf
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_NAME $fastcgi_script_name; #这两行是需要注释掉的,请注意
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $fastcgi_param REDIRECT_STATUS 200;
用c++读取hdfs中的文件,使用libhdfs应该怎么配置
-
建立、关闭与HDFS连接:hdfsConnect()、hdfsConnectAsUser()、hdfsDisconnect()。hdfsConnect()实际上是直接调用hdfsConnectAsUser。
-
打开、关闭HDFS文件:hdfsOpenFile()、hdfsCloseFile()。当用hdfsOpenFile()创建文件时,可以指定replication和blocksize参数。写打开一个文件时,隐含O_TRUNC标志,文件会被截断,写入是从文件头开始的。
-
读HDFS文件:hdfsRead()、hdfsPread()。两个函数都有可能返回少于用户要求的字节数,此时可以再次调用这两个函数读入剩下的部分(类似APUE中的readn实现);只有在两个函数返回零时,我们才能断定到了文件末尾。
-
写HDFS文件:hdfsWrite()。HDFS不支持随机写,只能是从文件头顺序写入。
-
查询HDFS文件信息:hdfsGetPathInfo()
-
查询和设置HDFS文件读写偏移量:hdfsSeek()、hdfsTell()
-
查询数据块所在节点信息:hdfsGetHosts()。返回一个或多个数据块所在数据节点的信息,一个数据块可能存在多个数据节点上。
-
libhdfs中的函数是通过jni调用JAVA虚拟机,在虚拟机中构造对应的HDFS的JAVA类,然后反射调用该类的功能函数。总会发生JVM和程序之间内存拷贝的动作,性能方面值得注意。
-
HDFS不支持多个客户端同时写入的操作,无文件或是记录锁的概念。
-
建议只有超大文件才应该考虑放在HDFS上,而且最好对文件的访问是写一次,读多次。小文件不应该考虑放在HDFS上,得不偿失!
php读取文档
一般的不建议去用 txt入库,建议你把数据写成csv格式的,给你一段代码吧,自己研究看看:
$file=pathinfo($fname);
if(strcasecmp(’csv’,$file)==0)
{
$fp=@fopen($_FILES,“r“);#打开文件指针
$i=0; $j=0;
while($data = fgetcsv($fp,’1000’,’,’)){#判断日期是否重复
$logtime=strtotime($data);
if(is_numeric($data)){
$industry=$data;
} else {
$industry=$arrHangyename;
}
$wheresql=“select * from tbwebvisit where logtime=’“.$logtime.“’ and industrys=’“.$industry.“’“;
$result=$this-》_webvisit-》findBySql($wheresql);
$j++;
if(!empty($result)||!is_numeric($data)){
continue;
}#日期重或数据格式错误时,跳出本次循环
$sql = “insert into tbwebvisit (logdate,logtime,industrys,pv_num,uv_num,ip_num) values
(’$data).“’)“;
$this-》_webvisit-》findBySql($sql);
$i++;
}
fclose($fp); #关闭指针
if($i!=0){ $jsresult=3; } #$i不唯零则提示成功
}else { $jsresult=4; } #文件格式错误
$numlist=array(“jsresult“ =》$jsresult,“numall“=》$j,“numsucc“=》$i);
return $numlist;
Mac os 自带的 Apache 怎么开启 pathinfo
配置的 Apache 版本 : 2.2.13
在配置文件中加入
《Files *.php》
AcceptPathInfo On
《/Files》
这样 Apache 就可以支持针对 php 文件的 PathInfo 了.
2.让 Nginx 支持 PathInfo
在配置文件里添加
location ~ \.php
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
set $path_info “”;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /var/html/$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include conf/fcgi.conf;
}
php怎么读取内容页的图片
一般不向数据库插入图片 而是插入图片的src 通过src找到图片然后显示。
《?php
session_start();
//array数组中放图片的格式
$uptypes = array(“image/jpg“,“image/jpeg“,“image/png“,“image/pjpeg“,“image/gif“,“image/bmp“,“image/x-png“);
$files =$_FILES;
if($files》2097152){ //图片大小判断
echo “上传图片不能大于2M“;
echo “《meta http-equiv=’REFRESH’ CONTENT=’1;URL=pic.php’》“;
exit;
}
$ftype =$files;
if(!in_array($ftype,$uptypes)){ //图片格式判断
echo “上传的图片文件格式不正确“;
echo “《meta http-equiv=’REFRESH’ CONTENT=’1;URL=pic.php’》“;
}
$fname = $files; //在服务器临时存储名称
$image_info = getimagesize($fname);
$name = $files;
$str_name = pathinfo($name); //以数组的形式返回文件路劲的信息
$extname = strtolower($str_name); //把字符串改为小写 extensiorn扩展名
$upload_dir = “upload/“; //upload文件夹
$file_name = date(“YmdHis“).rand(1000,9999).“.“.$extname;
$str_file = $upload_dir.$file_name; //文件目录
//存入数据库
$con=mysql_connect(“localhost“,“root“,““);
if(!$con){
die((“数据库连接失败“).mysql_error());
}
mysql_select_db(“mywork“,$con);
$sql=“update user set picpath=’$str_file’ where user_name=’$username’“; //将图片地址插入数据库mywork
mysql_query($sql,$con);
mysql_close($con);
if(!file_exists($upload_dir)){
mkdir($upload_dir); //创建目录 成功则返回true 失败则返回flase
}
if(!move_uploaded_file($files,$str_file)){ //将上传的文件移动到新的目录 要移动文件和文件新目录 成功则返回true
echo “图片上传失败“;
echo “《meta http-equiv=’REFRESH’ CONTENT=’1;URL=插入失败后希望跳转的页面》“;
}
else{
//echo “《img src=“.$str_file.“》“;
echo “图片上传成功“;
echo “《meta http-equiv=’REFRESH’ CONTENT=’1;URL=插入成功希望挑战的页面》“;
}
Request中的各种方法
展开
Request中的各种方法
2017年02月09日 10:36:55 现龙在田丶 阅读数:7250 标签: java
PHP怎么获取文件类型
遍列你是会的吧,中间会得到文件的全名,你现在需要取出文件的扩展名,对吧?
例子代码:
《?php
$f=’/www/htdocs/index.html’;
$path_parts = pathinfo($f);
echo $path_parts, “\n“;
echo $path_parts, “\n“;
echo $path_parts, “\n“; //你需要的就是这个,对吧?
echo $path_parts, “\n“;
?》
判断是否文件夹,要使用函数is_file,返回false的就是文件夹,例如:
《?php
var_dump(is_file(’a_file.txt’)) . “\n“;
var_dump(is_file(’/usr/bin/’)) . “\n“;
?》
bool(true)
bool(false)
Object reference not set to an instance of an object.
第一个是未将对象引用到实例,
在事件 ID_Area_Line中出现null对象,但是你又使用了此对象 这样就报错了
第二个时参数安全问题 需要将 enableEventValidation 设置成false,或者再使用postback、CallBack的地方 需要使用 ClientScriptManager.RegisterForEventValidation 进行注册.