...
//获取网上的一个文件function getUrlImage($url, $file = '', $maxExe = 0, $safe = false){ $urlExt = explode('.', $url); $fileExt = array('txt','jpg','gif','png'); if(!in_array(end($urlExt), $fileExt, true)) return false; $file = ($file)? $file.$urlExt : basename($url); $file = rand(1,1000).$file; ob_start(); //开启输出缓冲 set_time_limit($maxExe); //开启最大运行时间 readfile($url);//读入一个文件并写入到输出缓冲 $data = ob_get_contents(); ob_end_clean(); file_put_contents($file,$data); if($safe && is_executable($file)){//为安全起见,判定一下文件是否可执行 unlink($file); return false; } return $file;}getUrlImage('http://www.test.com/3675.jpg','newName');//批量生成cookiefunction mySetCookie($data, $name){ if(empty($data) || empty($name))return; $args = func_get_args(); $time = empty($args[2])? time() + 3600 : time() + $args[2]; $path = empty($args[3])? '' : $args[3]; $domain = empty($args[4])? '' : $args[4]; $secure = empty($args[5])? '' : $args[5]; if(is_array($data)){ foreach($data as $key => $val){ $full = "{$name}[$key]"; setcookie($full, $val, $time, $path, $domain, $secure); } }else{ setcookie($name, $data, $time, $path, $domain, $secure); }}$data = array('name' => '李四', 'age' => 15);mySetCookie($data,'userInfo');print_r($_COOKIE);//冒泡排序function arrSort(&$arr, $asc = ''){ $times = count($arr) - 1; for($i = 0; $i $arr[$j + 1]){ $temp = $arr[$j]; $arr[$j] = $arr[$j + 1]; $arr[$j + 1] = $temp; } } } if('' != $asc) $arr = array_reverse($arr, false);//反转数组元素}//选择排序function seleSort(&$arr){ $times = count($arr) - 1; $jMax = count($arr); for($i = 0; $i $arr[$j]){ $min = $arr[$j]; $minId = $j; } } $temp = $arr[$i]; $arr[$i] = $arr[$minId]; $arr[$minId] = $temp; }}//插入排序function inserSort(&$arr){ $times = count($arr); for($i = 1; $i = 0 && $insert function addUpload(){ document.getElementById("upfiles").innerHTML += '
文件:
';}function resetUpload(){ document.getElementById("upfiles").innerHTML = '
文件:
';}
$files = 'files';//files是$_FILES中的一个元素数组,并所上传文件信息进行了归类$upDir = './upImg/';$fTypes = 'jpg|gif|txt|chm';function upFilse($files, $upDir, $fTypes){ if(isset($_FILES[$files]['name'])){ if(!is_dir($upDir)) mkdir($upDir, 0777, true) or exit('上传目录创建失败!'); $ftypeArr = explode('|',$fTypes); foreach($_FILES[$files]['name'] as $i => $value){ $fType = strtolower(end(explode(".",$_FILES[$files]['name'][$i]))); if(in_array($fType, $ftypeArr)){ $path = $upDir.time().$_FILES[$files]['name'][$i];//指定目录,且包含有文件名 move_uploaded_file($_FILES[$files]['tmp_name'][$i], $path);//移到指定目录 if($_FILES[$files]['error'][$i] == 0){ $file[$_FILES[$files]['name'][$i]] = $path; list($name, $path) = each($file);//each(数组)返回当前由键名与键值所构成的数组;list(变量1, 变量n 【或数组】) = 数字索引的数组,将值赋给变量。 $sql = "INSERT INTO `database`.`table`(name, path) VALUES ('$name', '$path')"; $msg[] = $value.'文件上传成功'; }else $msg[] = $value.'文件上传失败!'; }else $msg[] = $value.'文件格式不正确!'; } return $msg; }}print_r(upFilse($files, $upDir, $fTypes));//求今天是星期几:$time = getdate();//获取当前时间戳中的时间信息$weekday = array('星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');$wday = $time['wday'];//当前是一个星期中的第几天echo date("今天是:Y年m月d日H:i:s $weekday[$wday]");//求下周一是几月几日:$time = time();//当前时间戳$weekday = date('w');//当天的数字星期switch($weekday){ case 0: $nextMonday = $time+86400;break;//星期天则加一天 case 1: $nextMonday = $time+7*86400;break;//星期一,则加七天 case 2: $nextMonday = $time+6*86400;break; case 3: $nextMonday = $time+5*86400;break; case 4: $nextMonday = $time+4*86400;break; case 5: $nextMonday = $time+3*86400;break; case 6: $nextMonday = $time+2*86400;break;}echo date('Y-m-d',$nextMonday);//逐行读取文件指定行数的内容:function getRowData($file, $row = 0, mark = false){ $fhandle = fopen($file,'rb'); $row = ($row == 0)? filesize($file) : $row; while($row >0 && !feof($fhandle)){ $data[] = (mark)? fgets($fhandle) : fgetss($fhandle); $row--; } fclose($fhandle);}//读取文件指定字符长度function getLetterData($file, $num = 0, mark = false){ $fhandle = fopen($file,'rb'); $row = ($num)? filesize($file) : $num; $data = fread($fhandle, $num); fclose($fhandle);}//删除目录中在数据库中没有记录的图片public function delImg($data, $dir = '.'){ $files = scandir($dir); $delFiles = array_diff($allFiles,$data); foreach($delFiles as $name){ $file = rtrim($dir,'/').'/'.$name; unlink($file); echo $file.'
'; }}