<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文件上传</title>
</head><body>
<form action="?a=up" method="post" enctype="multipart/form-data" name="form1" target="_self" id="form1">
<label>
<input name="f" type="file" id="f" />
</label>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</form>
<?php
$a=trim($_GET['a']);
if($a=='up' and isset($_POST)){
print_r($_FILES);
echo $_FILES[f][name];
$r=move_uploaded_file($_FILES[f][temp_ame],$_FILES[f][name]);
echo ($r)?'成功':'失败';
}
?>
</body>
</html>PHP.INI上传文件功能是开启的。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文件上传</title>
</head><body>
<form action="?a=up" method="post" enctype="multipart/form-data" name="form1" target="_self" id="form1">
<label>
<input name="f" type="file" id="f" />
</label>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</form>
<?php
$a=trim($_GET['a']);
if($a=='up' and isset($_POST)){
print_r($_FILES);
echo $_FILES[f][name];
$r=move_uploaded_file($_FILES[f][temp_ame],$_FILES[f][name]);
echo ($r)?'成功':'失败';
}
?>
</body>
</html>PHP.INI上传文件功能是开启的。
第二个参数应该是一个地址,而且php必须对这个地址有写权限。例(win下):
$r=move_uploaded_file($_FILES['f']['tmp_ame'],"d:/php/uploads/".$_FILES['f']['name']);
"d:/php/uploads/".basename($_FILES['f']['name']));
$r=move_uploaded_file($_FILES[f][tmp_name],basename($_FILES[f][name]));
如果是虚拟主机的话,不知道到底放在虚拟主机的那个盘里面了,只能是相对目录里面了,这样【"d:/php/uploads/".basename($_FILES['f']['name']));】应该还要改一下吧。
你可以 echo dirname(__FILE__);
看看,路径是什么样子的,然后,在指定目录吧。
如果没错的话,打印结果为该php文件所在目录
__FILE__意思了当前文件本身
php上传文件是很简单的
<?php
$a=trim($_GET['a']);
$path='D:/upload/';
if($a=='up' && $_FILES){
print_r($_FILES);
echo $_FILES['f']['name'];
$r=move_uploaded_file($_FILES['f']['temp_name'],$path.$_FILES['f']['name']);
echo ($r)?'成功':'失败';
}
?>