PHP-表單的讀寫,File檔案的操作等---ShinePans

來源:互聯網
上載者:User

標籤:php

實踐一:


表單的操作:


wlcome_page.php

<html><body><?phpinclude("menu1.php");?><form action="welcome_info.php" method="post"><br/>Name         :<input type="text" name="name"/><br/>Age          :<input type="text" name="age"/><br/>Adress       :<input type="text" name="address"/><br/>Phone pnumber:<input type="text" name="phone_number"/><br/><input type="submit"/></form></body></html>


welcome_info.php:


<html><body><font color="pink"><h1>Welcome!<?php echo $_POST["name"]?><br/><h1></font><font color="yellow"><h2>You are <?php echo $_POST["age"] ?>    years old.</h2></font>    <font color="green"><h2>Your Address is    <?php    echo $_POST["address"];    ?>    .</font></h2><br/>    <font color="blue"><h2>Your Phone number is     <?php    echo $_POST["phone_number"];    ?>    .</font></h2><br/></body></html>



menu1.php:

<html><body><a href="http://localhost:8080/php_test/wlcome_page.php">Home</a>|<a href="http://localhsot:8080/php_test/about1.php">About Us</a>|<a href="http://localhost:8080/php_test/contact.php">Contact Us</a></body></html>



表單顯示效果,填寫資訊:




實踐二檔案的上傳,檔案的讀取:
open_close_file_test.php:
<html><body><?php$num_of_char=0;$file=fopen("test_files1.txt","r+");//$file1=fopen("test_files2.txt","r") or exit("unable to open file!");//fclose($file1);/*下面的代碼是逐行讀取檔案的代碼,feof:判定是否讀到了檔案結束標誌fgets:逐行讀取檔案*/while(!feof($file)){echo fgets($file)."<br/>";}/*字數判定;*/$file1=fopen("test_files1.txt","r");while(!feof($file1)){if(fgetc($file1)!=' ')$num_of_char++;}echo "The test_files1.txt have the number of ".$num_of_char." chars";?><form action="upload_file.php" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><br/><input type="file" name="file" id="file"/><br/><input type="submit" name="submit" value="Submit"/>    </form></body></html>


upload_file.php

<html><body><?phpif($_FILES["file"]["error"]>0){echo "Error:".$_FILES["files"]["error"]."<br/>";}else{echo "Upload:".$_FILES["file"]["name"]."<br/>";echo "Type:".$_FILES["file"]["type"]."<br/>";echo "Size:".($_FILES["file"]["size"]/1024)."kb<br/>";echo "Stored in:".$_FILES["file"]["tmp_name"];}?></body></html>

效果顯示:




上傳後伺服器返回的資訊:




至此,表單的資訊擷取,檔案的上傳實踐至此.


PHP-表單的讀寫,File檔案的操作等---ShinePans

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.