我刚写的(也在学习中),
<FORM name=upload action="addpic.php" method=post encType=multipart/form-data>
<input name=pf type=file size=2600>
<INPUT name="image" type=submit width=34 height=19 border=0>
</form>
上面是表单
下面是接收文件
$uploaddir = "images/" . date("YmdHis_");
$uploadfile = $uploaddir. $_FILES['pf']['name'];
print "<pre>";
echo $uploadfile . "<br>" . $id;
if (move_uploaded_file($_FILES['pf']['tmp_name'], $uploadfile)) {
print "文件上传成功,下面是相关信息:\n";
print_r($_FILES);
} else {
print "文件上传失败,下面是相关信息:\n";
print_r($_FILES);
}
print "</pre>";
<FORM name=upload action="addpic.php" method=post encType=multipart/form-data>
<input name=pf type=file size=2600>
<INPUT name="image" type=submit width=34 height=19 border=0>
</form>
上面是表单
下面是接收文件
$uploaddir = "images/" . date("YmdHis_");
$uploadfile = $uploaddir. $_FILES['pf']['name'];
print "<pre>";
echo $uploadfile . "<br>" . $id;
if (move_uploaded_file($_FILES['pf']['tmp_name'], $uploadfile)) {
print "文件上传成功,下面是相关信息:\n";
print_r($_FILES);
} else {
print "文件上传失败,下面是相关信息:\n";
print_r($_FILES);
}
print "</pre>";
http://expert.csdn.net/Expert/topic/2420/2420457.xml?temp=.844494你看看如果还有别的问题 你可以现搜索一下 没有的话在来问嘛
还有FAQ里 自己去看啦!
ob_start("ob_gzhandler");
$adminpass='w8c'; //修改密码
?>
<?
@session_start();
if($action=="logout"){ //退出
session_unregister("okpwd");
session_register("okpwd");
$okpwd="";
echo "<script>window.close(\"this.window\");</script>";
}
if($pass!="")
{session_register("okpwd");
$okpwd=$password;
}
if($okpwd!=$adminpass)
{
echo"
<html>
<head><title>W8C 文件管理器 v1.8a</title>
<meta http-equiv=content-type content=text/html; charset=gb2312>
<link href=t.css rel=stylesheet type=text/css>
</head>
<body>
<table class=\"t1\" width=\"250\" cellspacing=\"1\" cellpadding=\"1\">
<tr>
<td class=\"t11\">W8C 文件管理器</td>
</tr>
<tr>
<form method=\"post\" action=\"\">
<td class=\"t12\">密码
<input type=\"password\" name=\"password\" maxlength=\"22\" size=\"17\">
<input type=\"submit\" name=\"pass\" value=\"登陆\"><br>
请勿回车!
</td>
</form>
</tr>
</table>
</body>
</html>
";
}
else
{
?>
<?
if ($downfile) {
if (!@is_file($downfile))
echo"你要下的文件不存在";
$filename = basename($downfile);
$filename_info = explode('.', $filename);
$fileext = $filename_info[count($filename_info)-1];
header('Content-type: application/x-'.$fileext);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Description: PHP3 Generated Data');
readfile($downfile);
exit;
}
?>
<?php
if($dir=="")
$dir="./";
?>
<?
if($tools==upload)
{
for($i=1;$i<21;$i++)
{
$temp1="userfile".$i;
$temp2="userfile".$i."_name";
$source=$$temp1;
$source_name=$$temp2;
if(@$source!="")
{
@$v=file_exists($filedir);
if(!$v)
{
mkdir(@$filedir,0777);
}
@chmod($filedir,0777);
if(file_exists("$filedir/$source_name")=="1")
{
if($up_flag=="y")
{
@unlink($filedir/$source_name);
@copy($source,"$filedir/$source_name");
echo $source_name."已覆盖上传<br>";
}
else
echo $source_name."请重新上传!<br>";
}
else
{
@copy($source,"$filedir/$source_name");
echo $source_name."已上传<br>";
}
}
}//end for
echo"
<html>
<head>
<title>W8C 文件管理器--多文件上传</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<link href=t.css rel=stylesheet type=text/css>
<script language=\"javascript\">
function setid()
{
str='<br>';
if(!window.uploadForm.upcount.value||window.uploadForm.upcount.value>20||window.uploadForm.upcount.value==0)
window.uploadForm.upcount.value=1;
for(i=1;i<=window.uploadForm.upcount.value;i++)
str+='文件'+i+':<input type=\"file\" name=\"userfile'+i+'\" style=\"width:400\" class=\"tx1\"><br><br>';
window.upid.innerHTML=str+'<br>';
}
</script>
</head>
<body>
<table width=\"550\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\">
<form name=\"t\" method=\"get\" action=\"?\">
<tr class=\"t2\">
<td><li> 1.指定上传目录(默认为本程序所在目录)
<input type=\"hidden\" name=\"tools\" value=\"upload\">
<input type=\"text\" name=\"dir\">
<input type=\"submit\" value=\"确定\" name=\"t\"></td></li>
</tr>
</form>
<form name=\"uploadForm\" method=\"post\" action=\"?tools=upload&dir=$dir\" enctype=\"multipart/form-data\">
<tr class=\"t2\">
<td>
<li> 2.需要上传的个数(建议最大值 20)
<input type=\"text\" name=\"upcount\" class=\"tx\" value=\"1\">
<input type=\"button\" name=\"Button\" class=\"bt\" onclick=\"setid();\" value=\"设定\">
</li>
<li> 3.全部文件都覆盖上传: <input type=\"radio\" name=\"up_flag\" value=\"y\">是<input type=\"radio\" name=\"up_flag\" value=\"n\" checked>否
</li>
<br>
<br>
您的文件将被上传到: $dir
<input type=\"hidden\" name=\"filedir\" class=\"tx\" value=\"$dir\">
<a href=\"?\">返回文件管理器</a>
</td>
</tr>
<tr>
<td id=\"upid\" height=\"122\"> 文件1:
<input type=\"file\" name=\"userfile1\" style=\"width:400\" class=\"tx1\" value=\"\">
</td>
</tr>
<tr>
<td>
<input type=\"submit\" name=\"upload\" value=\"上传\" class=\"bt\">
<input type=\"reset\" name=\"reset\" value=\"重执\" class=\"bt\">
</td>
</tr></form>
</table>
</body>
</html>";
exit;}
?><html>
<head><title>W8C 文件管理器 v1.8a</title>
<meta http-equiv=content-type content=text/html; charset=gb2312>
<link href=t.css rel=stylesheet type=text/css>
</head>
<body>
<?
if($action=="ren"){
echo"
把文件".$filename."改名为<form action=\"\" method=\"put\">
<input type=\"hidden\" name=\"dir1\" value=\"$dir\">
<input type=\"hidden\" name=\"filename\" value=\"$filename\">
<input type=\"text\" name=\"ren_name\">
<input type=\"submit\" name=\"action\" value=\"确定\"></form>
<a href=\"?dir=$dir\">--返回</a>
</body></html>";
exit;
}
elseif($action1=="ren"){
echo"
把目录".$filename."改名为<form action=\"\" method=\"put\">
<input type=\"hidden\" name=\"dir1\" value=\"$dir\">
<input type=\"hidden\" name=\"filename\" value=\"$filename\">
<input type=\"text\" name=\"ren_name\">
<input type=\"submit\" name=\"action1\" value=\"确定\"></form>
<a href=\"?dir=$dir\">--返回</a>
</body></html>";
exit;
}
?>
<?
if($tools==editfileperm) //编辑属性
{
$perm=substr(base_convert(fileperms("$dir/$fileperm"),10,8),-4);
echo"
<table class=\"t1\" width=\"750\" cellspacing=\"1\" cellpadding=\"1\">
<form method=\"post\" action=\"?dir=$dir&fileperm=$fileperm\">
<tr><td class=\"t11\">文件属性修改 <a href=\"?dir=$dir\">--返回</a>
</td></tr>
<tr><td class=\"t12\">$fileperm 属性为:
<input type=\"text\" name=\"perming\" value=\"$perm\">
<input type=\"submit\" name=\"editperm\" value=\"修改\">
<input type=\"reset\" value=\"重置\">
</td></tr>
<tr><td class=\"t12\">文件属性值请用八进制
<select name=\"fid\">
<option value=\"1\">0644</option>
<option value=\"2\">0755</option>
<option value=\"3\">0777</option>
</select>
<input type=\"submit\" name=\"editperm1\" value=\"选择修改\">
</td></tr></form>
</table>
</body></html>";
exit;
}
?>(未完)
if ($editfile!=""&&$action!='copy'&&$n=='1'||$newfile!="")//编辑文件
{
if($newfile==""){
$filename = "$dir/$editfile";
$fd = @fopen( $filename, "r" );
$contents = @fread($fd, filesize($filename));
@fclose( $fd );
$contents= str_replace("///textarea>","////textarea>",$contents);
}else{
$editfile=$newfile;
$filename = "$dir/$editfile";
}
echo"
<form name=\"edit\" method=\"post\" action=\"\">
<tr>
<td class=\"t11\">
当前文件:
<input type=\"text\" name=\"editfilename\" value=$editfile> 可以修改文件名 <a href=\"?dir=$dir\">--返回</a>
<br>复制:<input type=\"checkbox\" name=\"copy\" value=\"1\"> 注意:选中复制后,需给新文件改名,原文件内容不会变!<br>
<textarea name=\"editfiletxt\" cols=\"110\" rows=\"26\" style=\"background:#ffffff;border: 1px solid #500000;color:#500000\">$contents <///textarea>
<br>
<input type=\"hidden\" name=\"action\" value=\"copy\">
<input type=\"submit\" value=\"提交\">
<input type=\"reset\" value=\"重置\"></td></tr>
</form></body></html>";
exit;
}
?>
<h3>W8C 文件管理器 v1.8a</h3>
<table class="t2" width="750">
<tr>
<td width="100%">
程序路径:
<? $path="";
$pathname=str_replace('\\','/',dirname(__FILE__));
echo "<a href='?'>$pathname</a>";?>
<a href="?action=logout">退出管理</a>
<<< 转到 <a href="webftp.php">WebFTP</a></td>
</tr>
</table><br>
<table class="t1" width="750" cellspacing="1" cellpadding="1">
<form enctype="multipart/form-data" action="?dir=<? echo"$dir";?>" method="post" name="fm">
<tr class="t21">
<td class="t22" width="14%">选择文件:</td>
<td width="56%">
<input name="userfile" type="file"> <a href="?tools=upload"> 多文件上传</a>
</td>
<td rowspan="4" width="30%">
<?
if(!$userfile&&!$delfile&&!$deldir&&!$mkdir&&!$editfile&&!$editperm&&!$editperm1&&!$action&&!$action1)
{
echo"PHP版本: php".PHP_VERSION."<br>";
echo"操作系统: ".PHP_OS."<br>";
echo"解译引擎: ".getenv("SERVER_SOFTWARE")."<br>";
echo"脚本超时时间: ".get_cfg_var("max_execution_time")."秒<br>";
echo"服务器端口: ".getenv("SERVER_PORT");
echo"空间大小: ".@intval(diskfreespace("/") / (1024 * 1024)).'Mb<br>';
echo"可上传最大单文件: ".get_cfg_var("upload_max_filesize").'<br>';
echo"安全模式: ";
if (get_cfg_var("safe_mode"))echo"打开";
else echo"关闭";
}
?>
<?
if(@$userfile!="")
{
@$v=file_exists($filedir);
if(!$v)
{
mkdir(@$filedir,0777);
}
@chmod($filedir,0777);
if(@$lastname!="")
{
$lastname=$lastname;
}
else
$lastname=$userfile_name;
if(file_exists("$filedir/$lastname")=="1")
{
if($up_flag=="y")
{
@unlink($filedir/$lastname);
@copy($userfile,"$filedir/$lastname");
echo $userfile_name."已覆盖上传<br>";
}
else
echo $userfile_name."请选择文件,重新上传!<br>";
}
else
{
@copy($userfile,"$filedir/$lastname");
echo $userfile_name."已上传<br>";
}
}
?><?php
if(@$delfile!="")
{
if(file_exists($delfile))
{
@unlink($delfile);
}
else
{
$xx="1";
echo "文件已不存在<br>";
}
if(!file_exists($delfile)&&$xx!="1")
echo"删除成功";
else
echo"删除失败";
}
?>
<?php
if($deldir!="")
{
$deldirs="$dir/$deldir";
if(file_exists("$deldirs")) //是否为空目录
{
$mydir=@dir($deldirs);
while(@$files=$mydir->read())
{
$i=$i+1;
if($i>2)break;
}
$mydir->close(); //不关闭,后面就不能删除
}
if(file_exists("$deldirs")&&$i==2)
{
@chmod("$deldirs",0777);
@rmdir("$deldirs");
$xy="1";
}
if($i>2)
echo"此目录里有文件,要将整个目录全部删除,请点--<a href='?dir=$dir&deldir=$deldir&deltree=$deldir'>删除整个目录</a>";
if(!file_exists("$deldirs"))echo"目录不存在!";
if($xy=="1")echo"删除完必!";
}
?>
<?
if($mkdir)
{
$mkdirs="$dir//$mkdir";
if(file_exists("$mkdirs"))
echo"该目录存在";
else
{
@mkdir("$mkdirs",0777);
@chmod("$mkdirs",0777);
if(file_exists("$mkdirs"))
echo"目录创建成功";
else
echo"目录创建失败";
}
}
?>
<?
if($deltree!=""&&$deldir!="")
{
if($deltree==$deldir)
{
$deldirs="$dir/$deltree";
if(file_exists("$deldirs"))
{
deltree($deldirs);
echo"删除整个目录完必!<br>";
}else
echo"文件已不存在!<br>";
}
else
echo"错误操作!<a href='javascript:history.back(1)'>返回</a>";
}
?>(未完)
//编辑文件部分
if ($editfile!=""||$editfilename!="")
{
if($editfile!="")$filename1="$dir/$editfile";
else $editfile=$editfilename;
$filename="$dir/$editfilename";
if($copy!="1")
{
$editfiletxt=stripslashes("$editfiletxt");
$editfiletxt= str_replace("////textarea>","///textarea>",$editfiletxt);
writetofile("$filename","$editfiletxt");
if($editfile!=$editfilename)unlink($filename1);
if(file_exists($filename))
{
echo"写入成功";
}
elseif(!file_exists($filename))echo"失败";
}
if($copy=="1"&&$editfile==$editfilename)
{
echo"您要复制?必须给新文件改个名字,现在两个文件名相同,请<a href='javascript:history.back(1)'>返回</a>";
}
elseif($copy=="1"&&$editfile!=$editfilename){
echo"开始复制...<br>";
$lastfilename="$dir/$editfilename";
$editfiletxt=stripslashes("$editfiletxt");
$editfiletxt= str_replace("<////textarea>","<///textarea>",$editfiletxt);
writetofile("$lastfilename","$editfiletxt");
if(file_exists($lastfilename))echo"写入成功";
elseif(!file_exists($lastfilename))echo"失败";
}}
?>
<?if($editperm!="")//编辑属性部分
{
@chmod("$dir/$fileperm","$perming");
@$lastperm=substr(base_convert(fileperms("$dir/$fileperm"),10,8),-4);
echo"文件修改后的属性为$lastperm";
}
?>
<?if($editperm1!="")
{
if($fid=="1") {
@chmod("$dir/$fileperm",0644);}
if($fid=="2") {
@chmod("$dir/$fileperm",0755);}
if($fid=="3") {
@chmod("$dir/$fileperm",0777);}
@$lastperm=substr(base_convert(fileperms("$dir/$fileperm"),10,8),-4);
echo"文件修改后的属性为$lastperm";
}
?>
<?
if($action=="确定"){
$oldname=$dir1."/".$filename;
$newname=$dir1."/".$ren_name;
if(file_exists($newname)){
echo "<script>alert(\"该文件(".$newname.")已经存在,请返回重输一个\");
window.history.back(-1)</script>";exit;}
if(@rename($oldname,$newname))
echo $filename."改为".$ren_name."成功";
}
?>
<?
if($action1=="确定"){
$oldname=$dir1."/".$filename;
$newname=$dir1."/".$ren_name;
if(is_dir($newname)){
echo "<script>alert(\"该文件(".$newname.")已经存在,请返回重输一个\");
window.history.back(-1)</script>";exit;}
if(@rename($oldname,$newname))
echo $filename."改为".$ren_name."成功";
}
?>
</td>
</tr>
<tr class="t21">
<td class="t22" width="14%">上传的目录:</td>
<td width="56%"><input type="text" name="filedir" value="<? echo"$dir";?>"> 使用相对路径,可不写</td>
</tr>
<tr class="t21">
<td class="t22" width="14%">上传后的文件名:</td>
<td width="56%">
<input type="text" name="lastname" size="15"> 覆盖上传: <input type="radio" name="up_flag" value="y">是<input type="radio" name="up_flag" value="n" checked>否</td>
</tr>
<tr class="t21">
<td class="t22" width="14%"></td>
<td width="56%">
<input type="submit" value="上传">
<input type="reset" name="Submit" value="重置">
</td>
</tr>
</form>
</table>
<table class="t3">
<form name="t" method="get" action="">
<tr>
<td>当前路径: <? echo $NowDir = getMyPath($pathname, $dir);?>
<input type="text" name="dir" size="10">
<input type="submit" value="进入目录" name="t"></td>
</tr>
</form>
</table>
<table class="t1" width="750" cellspacing="1" cellpadding="1">
<tr class="t22">
<form method="post" action="?dir=<?echo"$dir";?>">
<td width="30%"> 目录:
<input type="text" name="mkdir" size="10">
<input type="submit" value="新建">
</td>
</form>
<form method="post" action="?action=newsfile&dir=<?echo"$dir";?>">
<td width="70%"> 文件:
<input type="text" name="newfile">
<input type="submit" value="新建">
</td>
</form>
</tr>
<tr class="t21">
<td width="30%">
<table width="100%">
<tr>
<td width="51%">目录名称</td>
<td width="15%">属性</td>
<td width="34%">操作</td>
</tr>
</table>
(未完)