温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php程序设计小示例有哪些

发布时间:2021-10-19 13:44:43 来源:亿速云 阅读:164 作者:小新 栏目:web开发

小编给大家分享一下php程序设计小示例有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

1、
check.php页面:


<?php
//图片上传到服务器

function fileext($filename)
  {
    return substr(strrchr($filename,'.'),1);  //获取扩展名
    
  }
function random($length)
  {  //生成随机文件名函数
    $hash='CR-';
    $chars='abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz';
    $max=strlen($chars)-1;
    mt_srand((double)microtime()*1000000);
      for($i=0;$i<$length;$i++)
       {
        $hash.=$chars(mt_rand(0,$max));
       }
       return $hash;
  }

?>

form.php页面:


<form action="upload.php" method="post" enctype="multipart/form-data"><!--定义method属性-->
      <table border="0" cellspacing="0" cellpadding="0" align="center" width="300px">
           <tr>
               <td width="55" height="20" align="center">
                  <input type="hidden" name="MAX_FILE_SIZE" value="2000000"/>文件:
               </td>
               <td height="16">
                   <input type="file" name="file" value="浏览"/>
               </td>
           </tr>
           <tr>
               <td align="center" colspan="2"><br />
                    <input type="submit" name="B1" value="上传"/>
               </td>
           </tr>
      </table>
</form>


upload.php页面:
<?php
  
   include("check.php");
   $uploaddir="./files?";
   $type=array("jpg","gif","bmp","jpeg","pan");//设置允许上传文件的类型
   if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type))//判断上传文件的类型是否在范围内
     {
        $text=implode(",",$type);
        echo "您只能上传以下类型文件:",$text,"<br/>";
     }else
       {
        $filename=explode(".",$_FILES['file']['name']);//获取文件名
        do{
            $filename[0]=random(10);
            $name=implode(".",$filename);
            $uploadfile=$upload.$name;
          }
        while(file_exists($uploadfile));
          if(is_uploaded_file($_FILES['file']['tmp_name']))
            {
                if(move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile))
                 {
                    echo "<center>您的文件已经上传完毕 上传图片预览:</center><br/><center><img src='$uploadfile'></center";
                    echo "<br/><center><a href='javascript:history.go(-1)'>继续上传</a></center>";
                 }else
                   {
                    echo "上传失败";
                   }
            }
       }
?>


2、

<!--在外部文件中读取并显示用户协议-->

<table width="100" border="0" cellpadding="1" cellspacing="1" bgcolor="#cccccc">
   <tr>
        <td bgcolor="#ffffff">
           <!--写文本内容要加载区-->
           
        </td>
   </tr>
</table>
<form action="zhuce.php" method="post" name="register" id="form">
      <input type="hidden" name="action" id="action" value="agree"/>
      <input type="submit" name="submit" value="同意"/>
</form>
<form action="" method="post" name="form" id="from">
      <a href="index.php">
           <input type="reset" name="reset1" id="reset1" value="不同意"/>
      </a>
</form>

以上是“php程序设计小示例有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI