[原创]php+ajax实现模拟Win文件管理系统
//
本教程由本站原创,转载请注明来处
作者:www.111cn.net
邮箱:drise@163.com
QQ:271728967
//
最后一个文件就是js.js文件了.
var xmlhttp=false;
function aa(obj)
{
obj.className='aa';
obj.onblur=function(){obj.className='bb';}
}
function resizepic(thispic) {
//$('imgbox').style.width = $('divbox').clientWidth;
if(thispic.height>55||thispic.width>55)thispic.style.zoom=56/(thispic.height>thispic.width?thispic.height:thispic.width);
}
function resizeimg(thispic){
if(thispic.height>100||thispic.width>100)thispic.style.zoom=180/(thispic.height>thispic.width?thispic.height:thispic.width);
}
上面这些是对图片进行缩放的.不过在fox也像有一点问题.
function Losefocus(obj,path){ //这里是创建文件时判断文件合法性,然后发带参数发送给rename.php文件,
var ivalue=obj.value;
if( 'New folder' == ivalue || !ivalue.match(/^\w{1,255}$/i)){
alert('输入合法文件夹名!');
obj.select();
return false;
}else{
CreateAjax();
var url="rename.php?path="+encodeURI(path.replace("/","\/"))+"&nname="+encodeURI(obj.value)+"&action=mkdir&rd="+Math.random();
Senddata('GET',url,ReturnValue,'mkdir');
document.getElementById('t1').innerHTML=ivalue;
window.location.reload();
}
}
下面还有今天就不写了,手都打痛了.明天接着来.
2008-01-24 00:00:00
//
本文由本站原创:www.111cn.net
作者:www.111cn.net
转载请注明:来自www.111cn.net
qq:271728967
//
早起一起突然看到,我的网站有人在恶心乱搞,为了防止这种事情我想了一个办法那就是封用户的IP了.
首页我们来建数据库:
CREATE TABLE `su_lockip` (
`id` int(4) NOT NULL auto_increment,
`lockip` varchar(1024) default NULL,
PRIMARY KEY (`id`)
)
下页来创建一个封文件的页面,主要是用户写入IP以"|"分开,这个页面就不多写了,我就简单的写一下,入库代码$UlockIp=$_POST['z']?$_POST['z']:'';
if(empty($UlockIp)){
exit("<script>alert('对不起,你输入的信息有误!');history.back();</script>");
}
$sql="update su_lockip set lockip='$UlockIp'";
if(mysql_query($sql)){
exit("<script>alert('锁定成功!');history.back();</script>");
}else{
exit("<script>alert('对不起,你输入的信息有误!');history.back();</script>");
}
就这么简单,最后就是进行锁定的了.下面代码是根据数据中是否存用户IP,如果在就提示被KILL了.代码如下:
function lock_user_ip(){
$Usql =mysql_query("select * from su_lockip");
$Urs =mysql_fetch_array($Usql);
$UlockIp=$Urs['lockip'];
$ClockIp=$this->get_real_ip();
$Iplist =explode('|',$UlockIp);
if(in_array($ClockIp,$Iplist)){
exit('sorry system lock your IP');
}
}
function get_real_ip(){//这段代码来是互联网.
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
哈哈写完了就这么简单,没有进行安全过滤处理.
[原创]php+ajax实现模拟Win文件管理系统
//本教程由本站原创,转载请注明来处
作者:www.111cn.net
邮箱:drise@163.com
QQ:271728967
//
上面php文件讲完了,下面来讲一下,document.js文件.些文件来自互联网.
var subMenuSrcObj=null;
function ShowMenu(obj,x,y){
try{
subMenuSrcObj=obj;
document.getElementById("subMenu").style.top=(ie_y(obj)+obj.offsetHeight+y)+"px";
document.getElementById("subMenu").style.left=(ie_x(obj)+x)+"px";
}catch(e)
{ ;
}
}
function loadsubMenu()
{
document.body.insertAdjacentHTML("afterBegin","<div id=\"subMenu\" style=\"filter:progid:DXImageTransform.Microsoft.DropShadow(color=#333333,offX=1,offY=1,positives=true);position:absolute; left:-10025px; top:47px; width:100px; height:1px;background-color: #D4D0C8;z-index:99999\">s</div>");
}
function hiddenSubMenu1()
{
document.getElementById("subMenu").style.left="-9000px";
}
function hiddenSubMenu()
{
try
{
obj=document.getElementById("subMenu");
temp=false;
e=event.srcElement;
if(e==obj)
{
temp=false;
}else
{
temp=true;
while(e=e.offsetParent)
{
if(e==obj||e==subMenuSrcObj)
{
temp=false;
}
}
}
if(event.srcElement==subMenuSrcObj)
{
temp=false;
}
if(temp&&parseInt(obj.style.left)>0)
{
hiddenSubMenu1();
}
}
catch (e)
{
}
}
function ie_y(e){
var t=e.offsetTop;
while(e=e.offsetParent){
t+=e.offsetTop;
}
return t;
}
function ie_x(e){
var l=e.offsetLeft;
while(e=e.offsetParent){
l+=e.offsetLeft;
}
return l;
}
function del(){
}
function myMenuShow(obj,btn)
{
document.getElementById("subMenu").innerHTML="<li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" onclick=\"alert('"+btn+"');\" >剪 切</li> <li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\">复 制</li><li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" >粘 贴</li> <hr><li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" onclick=\"del("+btn+");\">删 除</li> <hr><li onMouseOver=\"this.style.backgroundColor='#F5FBFF'\" onMouseOut=\"this.style.backgroundColor=''\" onclick=\"alert('你单击文件名就可重命名!');\" >重命名</li><br/>";
ShowMenu(obj,0,0);
return false;
}
document.onmousemove=hiddenSubMenu;
attachEvent('onload', loadsubMenu);// JavaScript Document//等一下只要这样调用就行了.
上一篇
[原创]php+ajax实现模拟Win文件管理系统
//
本教程由本站原创,转载请注明来处
作者:www.111cn.net
邮箱:drise@163.com
QQ:271728967
//
就是deldir()函数了这个函数的功能是删除文件
function deldir($dir){
if(is_dir($dir)){
$rdir = $dir;
if($dirlist = scandir($rdir)){ //进行扫描目录
array_shift($dirlist);去除".."
array_shift($dirlist);去除"."
foreach($dirlist as $d){
$rd = $rdir.'/'.$d;
if(isset($d) && is_file($rd)){
unlink($rd);//删除文件
}else{
deldir($rd);//递归
}
}
rmdir($rdir);//删除空目录
}else{
return false;
}
}
return true;
}
这个函数也用了递归算法,进行目录与文件的删除,
下面就是filename()函数了,这个函数的功能是对文件进行重命名
function Filename($path,$nname){
// 取得旧文件名
if($path == "" || substr($path,-1) =="/" || strlen($path)>255){
exit('非法操作!');
}else{
$oname = substr($path,strrpos($path,"/")+1);
$opath = substr($path,0,strlen($path) - strlen(substr($path,strrpos($path,"/")+1)));//获取文件的当前路径
}
//重命名
if(preg_match("/^\w{1,255}\.\w{1,8}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}\.\w{1,8}$/i",$oname,$otemp_name)){ //匹配文件名
Rename_file_folder($path,$opath,$nname);//些函数下面讲到
}else if( preg_match("/^\w{1,255}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}$/i",$oname,$otemp_name)){ //匹配文件夹名
Rename_file_folder($path,$opath,$nname);
}else{
echo("File info Error");
}}
function Rename_file_folder($path,$opath,$newname){
if(is_dir($path)){
if(is_writable($path)){
if(is_dir($opath.$newname)){ exit("Sorry Dir is exists");}
echo rename($path,$opath.$newname)?'Rename Success':'Rename Fail Error';
}else{
echo('Can\'t Rename dir not is_writable');
}
}else{
if(file_exists($path) && is_writable($path)){
if(file_exists($opath.$newname)){ exit("file exists"); }
echo rename($path,$opath.$newname)?'Rename success ':'Rename fail';
}else{
echo "file can't is_writable";
}
}
}
上一篇
[原创]php+ajax实现模拟Win文件管理系统
//本教程由本站原创,转载请注明来处
作者:www.111cn.net
邮箱:drise@163.com
QQ:271728967//
上面我们讲到了,Deletefile()函数,下面我们接着讲Createfolder()函数
function Createfolder($path,$nname){
if(is_dir($path) && is_writable($path)){//是否为目录且可写
if(preg_match("/^\w{1,255}$/i",$nname)){//判断文件的合法性
echo mkdir($path."/".$nname,0777)?'Create Folder success':'Create Folder Fail';//0777是设置文件可读写
}else{
echo "Folder Error";
}
}else{
echo "Can't Create Error file not is_writable or not dir";
}}
这个函数的功能是实现文件夹的建,
Past($path,$nname,$cpath)函数
function Past($currentpath,$currentfilename,$filepote){ //1:文件要被粘贴到的位置2:当前文件{夹}名3:文件{夹}所在的物理地址
$str = substr($currentfilename,-1,1);
if(substr($currentfilename,-1,1)=="|"){
$currentfilename = str_replace("|","",$currentfilename);
$filepote = str_replace("|","",$filepote);
}
if(is_dir($currentpath) && is_writable($currentpath) && is_dir($filepote) && is_writable($filepote)){
//@mkdir($currentpath."/".$currentfilename);
$t=full_copy($filepote,$currentpath."/".$currentfilename)?'t':'f';//full_copy函数下面接,是进行递归读取文件夹
}else if(is_file($filepote) && file_exists($filepote)){
if(file_exists($currentpath.$currentfilename)){ echo ('file exists! plase rename it!');exit;}
echo copy($filepote,$currentpath.$currentfilename)?'success':'errror';
} if( $str =="|" && $t='t' ){
deldir($filepote);
}
}
function full_copy( $source, $target )//这个函数来自php官方站,功能是进行文件夹递归拷贝文件
{
if ( is_dir( $source ) )
{
@mkdir( $target );
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) )
{
if ( $entry == '.' || $entry == '..' )
{
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) )
{
full_copy( $Entry, $target . '/' . $entry );
continue;
}
copy( $Entry, $target . '/' . $entry );
}
$d->close();
}else {
copy( $source, $target );
}
}
上一篇