PHP l2: Difference between revisions

From Ilianko
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:PHP]]
[[Category:PHP]]
Файлове
include();
require();
<code><pre>
<?php
if( isset($_POST['submit']))
{
$handle = fopen('vote', 'a');
fwrite($handle, $_POST['images'].': '.$_POST['vote']."\n\r");
fclose($handle);
}
?>
<!DOCTYPE html>
<html>
<head></head>
<body style="text-align:center">
<?php
$dir = opendir("images");
$images = array();
while( $filename = readdir($dir) )
{
if( !is_dir( "images/".$filename ))
{
$images[] = $filename;
}
}
$image = $images[ rand(0, sizeof($images)-1)];
   
$image2 =  $image;
    while( $image == $image2 )
    {
$image2 = $images[ rand(0, sizeof($images)-1)];
}
?>
<form action="" method="POST">
<input type="hidden" name="images" value="<?= $image.' - '.$image2 ?>" />
<div style="float:left">
<img width="400" height="300" src="images/<?php echo $image ?>" alt="pejzazh" title="landscape" /><br />
<input type=radio name=vote value=<?= $image ?> />
</div>
<div style="float:left">
<img width="400" src="images/<?php echo $image2 ?>" alt="pejzazh" title="landscape" /><br />
<input type=radio name=vote value=<?= $image2 ?> />
</div>
<div style="clear:both"></div>
<input type="submit" name="submit" value="VOTE" />
</form>
<?php
$handle = fopen('vote','r');
while( $line = fgets($handle) )
{
echo $line.'<br />';
}
fclose($handle);
?>
</body>
</pre></code>
include_once()
require_once()
Функции
Функции
[[PHP 3]]


Файлове


Класове
Класове
клас/обект/инстанция/абстракция/капсулиране/наследяване/метод/свойство/видимост

Latest revision as of 11:55, 9 November 2015

Файлове include(); require();


<?php
	
	if( isset($_POST['submit']))
	{
		$handle = fopen('vote', 'a');
		fwrite($handle, $_POST['images'].': '.$_POST['vote']."\n\r");		
		fclose($handle);
	}
?>
<!DOCTYPE html>
<html>
	<head></head>
	<body style="text-align:center">
		<?php
			$dir = opendir("images");
			$images = array();
			while( $filename = readdir($dir) )
			{
				if( !is_dir( "images/".$filename ))
				{
					$images[] = $filename;
				}
			}			
		
			$image = $images[ rand(0, sizeof($images)-1)];
		    
			$image2 =  $image;
		    while( $image == $image2 )
		    {
				$image2 = $images[ rand(0, sizeof($images)-1)];
			}
		
		
		?>
		
	<form action="" method="POST">
		<input type="hidden" name="images" value="<?= $image.' - '.$image2 ?>" />	

		<div style="float:left">
		<img width="400" height="300" src="images/<?php echo $image ?>" alt="pejzazh" title="landscape" /><br />
		<input type=radio name=vote value=<?= $image ?> />
		</div>
		
		
		<div style="float:left">
		<img width="400" src="images/<?php echo $image2 ?>" alt="pejzazh" title="landscape" /><br />	
		<input type=radio name=vote value=<?= $image2 ?> />
		</div>
		
		<div style="clear:both"></div>
		
		<input type="submit" name="submit" value="VOTE" /> 
	
	</form>
	<?php
		
		$handle = fopen('vote','r');
		
		while( $line = fgets($handle) )
		{
			echo $line.'<br />';
		}
		fclose($handle);
	
	?>
	</body>



include_once() require_once()


Функции PHP 3


Класове клас/обект/инстанция/абстракция/капсулиране/наследяване/метод/свойство/видимост