<?php
/**
* 递归创建目录
* @param $path
* @param $mode
* @return
*/
function mkdirs($path, $mode = 0777)
{
$dirs = explode('/',$path);
$pos = strrpos($path, ".");
if ($pos === false) {
$subamount=0;
}
else {
$subamount=1;
}
for ($c=0;$c < count($dirs) - $subamount; $c++) {
$thispath="";
for ($cc=0; $cc <= $c; $cc++) {
$thispath.=$dirs[$cc].'/';
}
if (!file_exists($thispath)) {
mkdir($thispath,$mode);
}
}
}
// 获取客户端IP地址
function get_client_ip() {
static $ip = NULL;
if ($ip !== NULL) return $ip;
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$pos = array_search('unknown',$arr);
if(false !== $pos) unset($arr[$pos]);
$ip = trim($arr[0]);
}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif (isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
}
// IP地址合法验证
$ip = (false !== ip2long($ip)) ? $ip : '0.0.0.0';
return $ip;
}
$handle = @fopen("1.txt", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = trim(fgets($handle));
$buffer = substr($buffer,1);
$subforder = date('YmdHi');
if (get_client_ip() == '127.0.0.1') {
$subforder .= 'local';
}
$tofile = './'.'release_backfile/'. $subforder . '/' . $buffer;
mkdirs($tofile);
if (!@copy($buffer, $tofile)) {
echo "copy('$buffer','$tofile' <span style='color:red'>failed</span>);<br />";
} else {
echo "copy('$buffer', <span style='color:green'>success</span>);<br />";
}
}
fclose($handle);
}
?>