标签:
1.html文件
- <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="keywords" content="关键字"> <meta name="description" content="简介"> <link rel="stylesheet" type="text/css" href="index.css"> <script src=""></script> </head> <body> <form action="reg.php" method="post" enctype="multipart/form-data"> 用户名:<input type="text" name="user"><br> 上传图片:<input type="file" name="file"><br> <input type="submit" name="submit" value="提交"> </form> </body> </html>
<?php//先创建user文件夹,在本地的服务器htdocs目录下session_start();if(isset($_POST[‘user‘])){//$u=iconv(‘utf-8‘,‘gbk‘,trim($_POST[‘user‘]));$u=trim($_POST[‘user‘]);$ip=str_replace(‘.‘,‘-‘,$_SERVER[‘REMOTE_ADDR‘]);//获取注册用户的ip,为文件夹的名字if($u==‘‘){echo ‘请填写用户名‘;}else if(file_exists(‘user/‘.$ip.‘.txt‘)){echo ‘此用户已经注册过‘;}else{// echo iconv(‘gbk‘,‘utf-8‘,$u);file_put_contents(‘user/‘.$ip.‘.txt‘,$u);echo ‘注册成功‘;}}
<?phpif(isset($_FILES[‘face‘])){echo ‘<pre>‘;print_r($_FILES);$f=$_FILES[‘face‘];if($f[‘error‘]==4){echo ‘没有文件上传‘;}else if($f[‘size‘]==0){echo ‘0字节的文件不用上传‘;}else if($f[‘type‘]!=‘image/jpeg‘){echo ‘请选择jpg图片格式文件‘;}else{move_uploaded_file($f[‘tmp_name‘],‘user/‘.$f[‘name‘]);echo ‘照片上传成功‘;}}
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><meta name="keywords" content="关键字"><meta name="description" content="简介"><link rel="stylesheet" type="text/css" href="index.css"><script src=""></script></head><body><form action="reg.php" method="post" enctype="multipart/form-data">照片:<input type="file" name="face"><br><input type="submit" value="上传照片"></form></body></html>
标签:
原文地址:http://www.cnblogs.com/lsr111/p/4523938.html