溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

php程序設(shè)計(jì)小示例有哪些

發(fā)布時(shí)間:2021-10-19 13:44:43 來源:億速云 閱讀:262 作者:小新 欄目:web開發(fā)

小編給大家分享一下php程序設(shè)計(jì)小示例有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

1、
check.php頁面:


<?php
//圖片上傳到服務(wù)器

function fileext($filename)
  {
    return substr(strrchr($filename,'.'),1);  //獲取擴(kuò)展名
    
  }
function random($length)
  {  //生成隨機(jī)文件名函數(shù)
    $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");//設(shè)置允許上傳文件的類型
   if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type))//判斷上傳文件的類型是否在范圍內(nèi)
     {
        $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>您的文件已經(jīng)上傳完畢 上傳圖片預(yù)覽:</center><br/><center><img src='$uploadfile'></center";
                    echo "<br/><center><a href='javascript:history.go(-1)'>繼續(xù)上傳</a></center>";
                 }else
                   {
                    echo "上傳失敗";
                   }
            }
       }
?>


2、

<!--在外部文件中讀取并顯示用戶協(xié)議-->

<table width="100" border="0" cellpadding="1" cellspacing="1" bgcolor="#cccccc">
   <tr>
        <td bgcolor="#ffffff">
           <!--寫文本內(nèi)容要加載區(qū)-->
           
        </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程序設(shè)計(jì)小示例有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI