文件上传

Posted on 2015-05-23 12:03  小蕊同学  阅读(123)  评论(0编辑  收藏  举报

1.html文件

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








Copyright © 2024 小蕊同学
Powered by .NET 9.0 on Kubernetes