|
动态网站开发中,常用的PHP上传文件的代码实例。
源码之家(mycodes.net)文件上传实例
[color=]function getname($exname){
[color=] $dir = "../uploadfile/";
[color=] $i=1;
[color=] if(!is_dir($dir)){
[color=] mkdir($dir,0777);
[color=] }
[color=] while(true){
[color=] if(!is_file($dir.$i.".".$exname)){
[color=] $name=$i.".".$exname;
[color=] break;
[color=] }
[color=] $i++;
[color=] }
[color=] return $dir.$name;
[color=]}
[color=]$exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
[color=]$uploadfile = getname($exname);
[color=]if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) {
echo "
[color=]文件上传成功!
";
[color=]}else {
echo "
[color=]文件上传失败!
";
[color=]}
[color=]echo "下面是文件上传的一些信息:
原文件名:".$_FILES['upfile']['name'] .
"
类型:" .$_FILES['upfile']['type'] .
"
临时文件名:".$_FILES['upfile']['tmp_name'].
"
文件大小:".$_FILES['upfile']['size'] .
"
错误代码:".$_FILES['upfile']['error'];
?>
|
|