PHP-form reading and writing, File file operations, etc.---ShinePans

WBOY
Release: 2016-08-08 09:31:51
Original
908 people have browsed it

Practice 1:

Form operation:

wlcome_page.php

<html>
<body>
	<?php
	include("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>
Copy after login

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>
Copy after login

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>
Copy after login


Form display effect, fill in information:



Practice 2

File uploading, file reading:

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>
Copy after login

upload_file.php

<html>
<body>
	<?php
	if($_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>
Copy after login

Effect Display:


Information returned by the server after uploading:


So far, the form information acquisition and file upload practice have ended.

The above introduces PHP-form reading and writing, File file operation, etc.--ShinePans, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template