Difference between revisions of "Talk:PHP u1v2"
From Ilianko
(Created page with "2. <code><pre><?php $files = array(); $dir = opendir('images'); while( $file = readdir($dir)) { if( !is_dir($file)) { $files[] = $file; }...") |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 16: | Line 16: | ||
?> | ?> | ||
<img src=images/<?php echo $filename; ?> alt="fourth image" title="fourth image" /> | <img src=images/<?php echo $filename; ?> alt="fourth image" title="fourth image" /> | ||
+ | </pre></code> | ||
+ | |||
+ | 3.<code><pre> | ||
+ | <?php | ||
+ | |||
+ | $files = array(); | ||
+ | $dir = opendir('images'); | ||
+ | |||
+ | while( $file = readdir($dir)) | ||
+ | { | ||
+ | if( !is_dir($file)) | ||
+ | { | ||
+ | $files[] = $file; | ||
+ | } | ||
+ | } | ||
+ | $filename1 = $files[rand(0, sizeof($files)-1)]; | ||
+ | |||
+ | $filename2 = $filename1; | ||
+ | while( $filename1 == $filename2 ) | ||
+ | { | ||
+ | $filename2 = $files[rand(0, sizeof($files)-1)]; | ||
+ | } | ||
+ | ?> | ||
+ | <img src=images/<?php echo $filename1; ?> alt="fourth image" title="fourth image" /> | ||
+ | <img src=images/<?php echo $filename2; ?> alt="fourth image" title="fourth image" /> | ||
+ | </pre></code> | ||
+ | <code><pre>4.<form action="" method="POST"> | ||
+ | |||
+ | <div style="float:left;text-align: center"> | ||
+ | <img src=images/<?php echo $filename1; ?> alt="fourth image" title="fourth image" /><br /> | ||
+ | <input type="radio" name=voteValue value=<?= $filename1 ?> /> | ||
+ | </div> | ||
+ | |||
+ | <div style="float:left;text-align: center"> | ||
+ | <img src=images/<?php echo $filename2; ?> alt="fourth image" title="fourth image" /><br /> | ||
+ | <input type="radio" name=voteValue value=<?= $filename2 ?> /> | ||
+ | </div> | ||
+ | <div style=clear:both></div> | ||
+ | |||
+ | <div><input type="submit" name=vote value=Vote /></div> | ||
+ | </form> | ||
+ | </pre></code> | ||
+ | |||
+ | 5.<code><pre> | ||
+ | <input type="hidden" name=images value="<?= $filename1.' - '.$filename2 ?>" > | ||
+ | |||
+ | |||
+ | if( isset($_POST['vote'])) | ||
+ | { | ||
+ | $handle = fopen('vote', 'a'); | ||
+ | fwrite($handle, $_POST['images'].': '.$_POST['voteValue']."\n\r"); | ||
+ | fclose($handle); | ||
+ | } | ||
+ | |||
+ | </pre></code> | ||
+ | 6<code><pre> | ||
+ | <?php | ||
+ | $handle = fopen('vote','r'); | ||
+ | while( $line = fgets($handle)) | ||
+ | { | ||
+ | echo $line.'<br />'; | ||
+ | } | ||
+ | ?> | ||
+ | </pre></code> | ||
+ | |||
+ | |||
+ | <code><pre> | ||
+ | $file = explode(':', $line); | ||
+ | if ( isset( $file[1])) | ||
+ | echo $line.'<img height=60 width=80 src=images/'.trim($file[1]).' /><br />'; | ||
+ | </pre></code> | ||
+ | |||
+ | <code><pre> | ||
</pre></code> | </pre></code> |
Latest revision as of 21:15, 8 November 2015
2.
<?php
$files = array();
$dir = opendir('images');
while( $file = readdir($dir))
{
if( !is_dir($file))
{
$files[] = $file;
}
}
$filename = $files[rand(0, sizeof($files)-1)];
?>
<img src=images/<?php echo $filename; ?> alt="fourth image" title="fourth image" />
3.
<?php
$files = array();
$dir = opendir('images');
while( $file = readdir($dir))
{
if( !is_dir($file))
{
$files[] = $file;
}
}
$filename1 = $files[rand(0, sizeof($files)-1)];
$filename2 = $filename1;
while( $filename1 == $filename2 )
{
$filename2 = $files[rand(0, sizeof($files)-1)];
}
?>
<img src=images/<?php echo $filename1; ?> alt="fourth image" title="fourth image" />
<img src=images/<?php echo $filename2; ?> alt="fourth image" title="fourth image" />
4.<form action="" method="POST">
<div style="float:left;text-align: center">
<img src=images/<?php echo $filename1; ?> alt="fourth image" title="fourth image" /><br />
<input type="radio" name=voteValue value=<?= $filename1 ?> />
</div>
<div style="float:left;text-align: center">
<img src=images/<?php echo $filename2; ?> alt="fourth image" title="fourth image" /><br />
<input type="radio" name=voteValue value=<?= $filename2 ?> />
</div>
<div style=clear:both></div>
<div><input type="submit" name=vote value=Vote /></div>
</form>
5.
<input type="hidden" name=images value="<?= $filename1.' - '.$filename2 ?>" >
if( isset($_POST['vote']))
{
$handle = fopen('vote', 'a');
fwrite($handle, $_POST['images'].': '.$_POST['voteValue']."\n\r");
fclose($handle);
}
6
<?php
$handle = fopen('vote','r');
while( $line = fgets($handle))
{
echo $line.'<br />';
}
?>
$file = explode(':', $line);
if ( isset( $file[1]))
echo $line.'<img height=60 width=80 src=images/'.trim($file[1]).' /><br />';