mercredi 28 janvier 2015

Create variable $pathinfo and $random to get block 15 random lines of html file

I am working on a php website and would like to echo 15 random line from a html file. So far I just got 15 lines but the problem is I get the code from the html file and not 15 block lines from the text. How could I define 2 variables $pathinfo and $random to write my code in a way that gets me the correct solution?


My code:



<?php

$selected_file = $_POST['radio1'];
// get the filename of the file
$fileinfo = pathinfo($selected_file);
$filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename'];
$password = 'code';




if (isset($_POST['submitradio']))
{
echo '<div class="imageselected">';
echo '<img src="'.$selected_file.'" /></br>'.PHP_EOL;
echo '</div>';
// check to see if a html file named the same also exists
if(file_exists("$filename.html"))
{

echo "<form action='test_result.php' method='post'>";
echo '<div class="Password">';
echo 'Type in password to view full Script';

echo "<label><div class=\"Input\"><input type='password' name='passIT' value='passit'/></div>";
echo "<input type='submit' name='submitPasswordIT' value='Submit Password'/></div>";
echo '</div>';
echo '</form>';
echo "$filename.html shares the same name as $selected_file";



$lines = file("$filename.html");

for($x = 1;$x<=15;$x++) {

echo $lines [rand(0, count($lines)-1)]."<br>";
}
// end of forloop

}
// end of check
// start Sorrytext

else
{
echo '<div class="NoScript">';

echo "We apologize. No Script available for this movie.";
echo '</div>';
}

// end Sorrytext
}
// End of submitradio
if($_POST['submitPasswordIT']){
if ($_POST['passIT']== $password ){
echo "You entered correct password";
$dirs = glob("*", GLOB_ONLYDIR);
$pathinfo = ($dirs.'/'.$lines.'/html');
include($pathinfo);
}
else{
echo "You entered wrong password";
}
}

?>


Help would be very much appreciated:)





Aucun commentaire:

Enregistrer un commentaire