PHP l2

From Ilianko
Revision as of 11:55, 9 November 2015 by Anko (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Файлове 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


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