php 批量重命名文件

如何用php批量重命名文件

/**
 * php 批量重命名文件
 *
 * @return void
 */
function renamefiles()
{
    paths = "/path";d = dir(paths);
    while (false !== (entry = d->read())) {

        if(entry == '.' || entry == '..'){

        } else {

        }

        if(strpos(entry, '.mp4')){
            // echo paths.entry;
            // echo "原 ".entry;

            echo "<br>";

            //newname = strtr(entry, '-t=18121111.htm', '');             /*把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":
                echo str_replace("world","Shanghai","Hello world!");
                substr(string,start,length)*/newname = substr(entry, 0, 2).".mp4";

            echonewname;

            echo "<br>";       

            rename(paths.entry, paths.newname);
        }


    }
    $d->close();
    echo "done";
}

php绕开ssl验证&获取包含headers的所有response

<?php
curl = curl_init();url= "https://testapi.xxxx.author/signin";
email =_POST["email"];
pwd =_POST["password"];
curl_setopt_array(curl, array(
  CURLOPT_URL =>url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "email=".email."&password=".pwd,
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/x-www-form-urlencoded",
    "postman-token: 1ebc8292-5e01-a6fa-9f91-26d3126892e0"
  ),
));

curl_setopt(curl, CURLOPT_HEADER, true);//get all respose include headers&body
curl_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); //pass https ssl verification

//result = curl_getinfo(curl, CURLINFO_HTTP_CODE);
//headers = apache_request_headers();response = curl_exec(curl);err = curl_error(curl);

curl_close(curl);

if (err) {
  echo "cURL Error #:" .err;
} else {
  echo $response;
}
?>

最简单的php写入数据库

最简单的php写入数据库,小程序测试用

<?php

  function writetosql(){
      servername = "localhost";username = "root";
        password = "123456";dbname = "test";
        ts = time();fname = _POST["name"];type = _POST["tt"];note = _POST["note"]?_POST["note"]:"小懒虫";

        // 创建连接
        conn = new mysqli(servername, username,password, dbname);
        // 修改数据库连接字符集为 utf8
        mysqli_set_charset(conn,"utf8");
        // 检测连接
        if (conn->connect_error) {
            die("连接失败: " .conn->connect_error);
        } 

        sql = 'INSERT INTO test(fname,type,note,time)VALUES("'.fname.'","'.type.'","'.note.'","'.

ts.'")';
        //echosql;

        if (conn->query(sql) === TRUE) {
            echo "新记录插入成功";
        } else {
            echo "Error: " . sql . "<br>" .conn->error;
        }

        $conn->close();

  }
?>

xampp httpd-vhosts.conf配置多个虚拟目录

1: 用记事本打开C:/WINDOWS/system32/drivers/etc/hosts文件,配置如下:

127.0.0.1 localhost
127.0.0.1 phptest.com

2:因为我xampp是装在C盘的:用记事本打开C:\xampp\apache\conf\httpd.conf文件,找到Include conf/extra/httpd-vhosts.conf,确认前面没有加#.
2.1找到
[code]
<Directory />
AllowOverride none
Require all denied
</Directory>
[/code]
修改权限,变成:
[code]
<Directory />
Order deny,allow
Allow from all
</Directory>
[/code]

2.2在此文件末尾添加如下内容:
[code]
<Directory "D:/eclipse-php/workspace">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
[/code]

3:打开C:\xampp\apache\conf\extra\httpd-vhosts.conf,在此文件末尾添加如下内容:
[code]
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>

<VirtualHost *:80> //如果配置不同的端口号88,则需要在httpd.conf里面添加 Listen 88
DocumentRoot "D:/eclipse-php/workspace"
ServerName phptest.com
</VirtualHost>
[/code]

5:重启Apache服务即可。

php解压swf

<?php  
//文件名
filename = "test.swf";
//打开文件rs = fopen(filename,"r");
//读取文件的数据str = fread(rs,filesize(filename));
//check compress status
check = substr(str,0,1);
if(check=="C")
{
	echo "这是一个压缩文件,下面解压";
//设置swf头文件head = substr(str,1,7);head = "F".head;
//获取swf文件内容body = substr(str,8);
//解压缩文件内容body = gzuncompress(body);
//合并文件头和内容str = head.body;
//关闭读取的文件流
fclose(rs);
//创建一个新的文件ws = fopen("jieya.swf","w");
//写文件
fwrite(ws,str);
}else if(check=="F")
{
	echo "这是一个没有压缩的文件,下面开始压缩";head = substr(str,1,7);head = "C".head;body = substr(str,8);body = gzcompress(body, 9);str = head.body; 
fclose(rs);ws = fopen("yasuo.swf","w");  
fwrite(ws,str);  
}else
{
  echo "这不是一个合法的flash文件";
}
//关闭文件
fclose($ws);
?>