IIS上跑PHP,遭遇上传权限问题

其实这个问题不关IIS以及PHP什么事,是我的权限没设置好。

在使用PHP上传文件时,一直报错,错误信息如下:

PHP Warning: move_uploaded_file(): Unable to move ‘C:\Windows\Temp…

一开始以为是C:\Windows\Temp的权限问题,结果加上IUSR,并给予所有权限后,还是不行。

然后又给uploads文件夹给IUSR账户所有权限,结果还是不行。

最后在uploads文件上给IIS_IUSERS账户加上所有权限后,问题解决。

总结:

问题的主要原因是我没有弄清楚IIS的两个账户分别是什么意思,关于IUSR和IIS_IUSER的区别。

简单查了一下,知道 IUSR is part of IIS_IUSER group

基本的PHP上传文件

基本的PHP上传文件

表单:

<form id ="form1" method="POST" enctype="multipart/form-data" >
<input name ="room_logo" type="file"  value="" id ="room_logo" class="input normal"   sucmsg=" " />
</form>

注意:表单上要加 enctype=”multipart/form-data” 

PHP处理代码:

<?php
$method = $_SERVER['REQUEST_METHOD' ];
if ($method == 'POST') { 
    $destination_folder ="../../uploads/"; //上传文件路径
    //是否存在文件
    if ( is_uploaded_file($_FILES ["room_logo"]["tmp_name" ])) {       
        $file = $_FILES["room_logo" ];
        if(!file_exists( $destination_folder )) {
            mkdir ($destination_folder);
        }
        $filename=$file["tmp_name"];
        $pinfo=pathinfo( $file["name" ]);
        $ftype=$pinfo['extension'];
        $destination = $destination_folder.time(). ".".$ftype ;
        if(!move_uploaded_file ($filename, $destination)){
            echo " 移动文件出错 ";
        }              
    }
}

?>

php fopen打开中文名的文件 

php fopen打开中文名的文件 :

注意要使用iconv将iconv转码为GBK,当前PHP文档是uft-8编码的。

$file_dir = dirname(__FILE__) . '\\';
$name = iconv ( 'UTF-8', 'GBK', '金科智能VR批量渲染加速系统免费版.rar' );  //从UFT8编码转到GBK编码

$file = fopen($file_dir.$name,"rb");

centos编译安装apache2.4.10 + PHP5.5

centos编译安装apache2.4.10 + PHP5.5全记录:

编译安装apache2.4.10

 从官方下载(链接需要改版本): 

wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.39.tar.gz
wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz
wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz

解压缩:

tar -xvf httpd-2.4.39.tar.gz
tar -xvf apr-1.7.0.tar.gz
tar -xvf apr-util-1.6.1.tar.gz

一点文件操作:

mv apr-1.7.0 httpd-2.4.39/srclib/apr
mv apr-util-1.6.1 httpd-2.4.39/srclib/apr-util
cd httpd-2.4.39

编译前安装 :

yum install zlib-devel pcre-devel

  编译命令:

./configure --prefix=/web/httpd --with-included-apr --enable-nonportable-atomics=yes --with-z

编译完成后:

make
make install

———————————-

wget http://cn2.php.net/distributions/php-5.5.18.tar.bz2
tar -xvf php-5.5.18.tar.bz2
cd php-5.5.18
./configure --prefix=/web/php --with-apxs2=/web/httpd/bin/apxs --enable-cli --enable-shared --with-libxml-dir --with-gd --with-openssl --enable-mbstring --with-mcrypt --with-mysqli --with-mysql --enable-opcache --enable-mysqlnd --enable-zip --with-zlib-dir --with-pdo-mysql --with-jpeg-dir --with-freetype-dir --with-curl --without-pdo-sqlite --without-sqlite3

PHP优化var_dump输出

PHP优化var_dump输出

 /**
 * 浏览器友好的变量输出
 * @param mixed $var 变量
 * @param boolean $echo 是否输出 默认为True 如果为false 则返回输出字符串
 * @param string $label 标签 默认为空
 * @param boolean $strict 是否严谨 默认为true
 * @return void|string
 */
function dump($var, $echo=true, $label=null, $strict=true) {
    $label = ($label === null) ? '' : rtrim($label) . ' ';
    if (!$strict) {
        if (ini_get('html_errors')) {
            $output = print_r($var, true);
            $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
        } else {
            $output = $label . print_r($var, true);
        }
    } else {
        ob_start();
        var_dump($var);
        $output = ob_get_clean();
        if (!extension_loaded('xdebug')) {
            $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
            $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
        }
    }
    if ($echo) {
        echo($output);
        return null;
    }else
        return $output;
} 

PHP获取页面中的所有链接

PHP获取页面中的所有链接

/*
*PHP获取页面中的所有链接
*/
function getPageLink($url)
{
   set_time_limit(0);
   $html=file_get_contents($url);
   if (!$html) {
          return false;
   }
   preg_match_all("/<a(s*[^>]+s*)href=([\"|']?)([^\"'>\s]+)([\"|']?)/ies",$html,$out);
   $arrLink=$out[3];
   $arrUrl=parse_url($url);
   $dir='';

   if(isset($arrUrl['path'])&&!empty($arrUrl['path'])){
        $dir=str_replace("\\","/",$dir=dirname($arrUrl['path']));
        if($dir=="/"){
             $dir="";
        }
   }

   if(is_array($arrLink)&&count($arrLink)>0){
        $arrLink=array_unique($arrLink);
        foreach($arrLink as $key=>$val){
             $val=strtolower($val);
             if(preg_match('/^#*$/isU',$val)){
                  unset($arrLink[$key]);
             }elseif(preg_match('/^\//isU',$val)){
                  $arrLink[$key]='http://'.$arrUrl['host'].$val;
             }elseif(preg_match('/^javascript/isU',$val)){
                  unset($arrLink[$key]);
             }elseif(preg_match('/^mailto:/isU',$val)){
                  unset($arrLink[$key]);
             }elseif(!preg_match('/^\//isU',$val)&&strpos($val,'http://')===FALSE){
                  $arrLink[$key]='http://'.$arrUrl['host'].$dir.'/'.$val;
             }
        }
   }
   sort($arrLink);
   return $arrLink;
}

PHP使用stripslashes会把HTML代码直接显示出来

PHP使用stripslashes会把HTML代码直接显示出来,而不是HTML代码的表现。

可以用htmlspecialchars_decode来让HTML表现出来。

有些时候必须要使用stripslashes,比如开启了magic_quotes_gpc,如果一个字符串中有引号之类的,PHP会自动给在单引号前加上双斜杠。这时,在使用的这个字符串的时候,就要用stripslashes()去掉,然后再用htmlspecialchars_decode来让HTML代码表现出来。

shit!

高版本的PHP中,magic_quotes_gpc这个特性已经移除了,我在PHP5.5和PHP5.5以上就没有发现这个问题。