Difference between revisions of "PHP l2"
From Ilianko
Line 6: | Line 6: | ||
<code><pre> | <code><pre> | ||
+ | <?php | ||
+ | |||
+ | if( isset($_POST['submit'])) | ||
+ | { | ||
+ | $handle = fopen('vote', 'a'); | ||
+ | fwrite($handle, $_POST['images'].': '.$_POST['vote']."\n\r"); | ||
+ | fclose($handle); | ||
+ | } | ||
+ | ?> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html> | <html> | ||
− | < | + | <head></head> |
− | + | <body style="text-align:center"> | |
− | + | <?php | |
− | + | $dir = opendir("images"); | |
− | < | + | $images = array(); |
− | < | + | while( $filename = readdir($dir) ) |
− | <div | + | { |
− | + | 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> | ||
+ | |||
+ | |||
+ | <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> | </body> | ||
− | |||
</pre></code> | </pre></code> |
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
Класове
клас/обект/инстанция/абстракция/капсулиране/наследяване/метод/свойство/видимост