Jump to content

IamTomCat

Members
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

0 Neutral

About IamTomCat

  • Rank
    Member
  1. hi I did read your response and I will work on that. But you know how it is with Php. I would very much like to figure out the things that I have asked for. For me it's just that I would like to know how to write a code like this. When you have a problem when coding php you don't rest until you did find the answer. You may understand what I mean. Help would be therefor very much appreciated.
  2. Hi Ch0cu3r. Thanks for your reply. I tried to improve what you said. But like it looks like I do it all wrong. My full code: session_start(); $selected_file = $_POST['radio1']; // get the filename of the file $fileinfo = pathinfo($selected_file); $filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename']; $password = 'Youarecrazy'; $lines = file("$filename.html"); $_SESSION['selectedfile'] = $selected_file; $_SESSION['file'] = $filename; $_SESSION['file2'] = $fileinfo; 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 '<div class="Password">'; echo 'Type in password your password'; 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 "$filename.html shares the same name as $selected_file"; for($x = 1;$x<=15;$x++) { $dom = $dom = new DOMDocument; $dom->loadHTML("$filename.html"); echo $dom[rand(0, count($dom)-1)]."<br>"; } // end of forloop } // end of check // start Sorrytext else { echo '<div class="HaWrong">'; echo "Ha. You got it all wrong."; echo '</div>'; } // end Sorrytext } // End of submit radio if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ echo "You entered wrong password"; echo readfile("$filename.html"); } else{ echo "You entered wrong password"; } } ?> How do I use sessions and HTML_DOM correctly?
  3. Hi I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems. 1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that? for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; } I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } } If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. // get the filename of the file $fileinfo = pathinfo($selected_file); $filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename']; You may need this lines to: $selected_file = $_POST['radio1']; // get the filename of the file $fileinfo = pathinfo($selected_file); $filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename']; Help would be very much appreciated.
  4. The output of : printf('<pre>%s</pre>', print_r($_POST, 1)); is: Array ( [radio1] => Animation/Despicable Me.jpg [submitradio] => submit ) Animation is the folder name. Despicable Me.jpg is the image name.
  5. Hi. Thanks for your reply and your patience. Well the files are in the same folder. And I don't get anything for that part: echo "$filename.html shares the same name as $selected_dir"; Have you tried it yourself? And when yes, did it work for you? Well I just wonder, if I may have made a mistake or if there could be maybe an other solution for the problem. I tried now for hours without making any progress.
  6. HI many thanks for your reply. I try to explain it again. I want that when I submit the radio button($selected_dir = $_POST['radio1']), ( which would be for example order.gif) and when there is a file in the same folder called "order.html" then I could for example echo out "boa boa". If I submit let's say a radio button value (let's say "smoke.gif") and there is no html file called "smoke.html" then I could echo out "No boa boa available". Don't know how else to explain it. It's just really important that I don't give actually the name of each file. I want that the programme looks what is there. Example of what I got with the code you gave me: Could not find a html file that shares the same order. But there is a file called order.gif and a file called order.html in the same folder. Help would be very much appreciated.
  7. Hi I want to echo out something when I post the value of a radio button and this value matches the same name of a html file. How can I formulate my code to achieve that? What I have so far: <?php if (isset($_POST['submitradio'])) { $selected_dir = $_POST['radio1']; echo substr($selected_dir, 0, -4); echo '<img src="'.$selected_dir.'" />'; } ?> So far I get for example the name of the image(order.gif) and the image order. gif. What I now want is to formulate my code so that I can say if I have an image called "order.gif" and a file called "order.html" that I can then echo out some thing. I don't want to actually name the image or the html file. I just want to say if I have two different file types that start with the same name then I can echo out what ever. How can I do that?
  8. Hi It is brilliant. You are a genius. Thank you so much Guru. P.S. foreach(glob($selected_dir . DIRECTORY_SEPARATOR . '*.{jpg,png}', GLOB_BRACE) as $dirname) //will only get files with .jpg and .png This code was exactly what I have been looking for
  9. Hi I echo out images from a folder. The problem is that I have a html file in the same folder but I don't want to echo that out. How can I write my code to get rid of the html in the output? Here my code: <?php $filetype = '*.html'; $dirname = substr('$filetype'); $i=0; if (isset($_POST['submit2'])) { //get the dir from POST $selected_dir = $_POST['myDirs']; //now get the files from within the selected dir and echo them to the screen foreach(glob($selected_dir . DIRECTORY_SEPARATOR . '*') as $dirname) { echo substr($dirname, 0, -4); echo '<img src="'.$dirname.'" />'; echo "<label><div class=\"radiobt\"><input type='radio' name='radio1' value='$i'/></div></label>"; } } ?> P.S. when I echo out : substr($dirname, 0, -4); I want to get ride of the html filename there too. How can I do so something like this?
  10. Hi. Many thanks for the reply. Unfortunat it didn't work. My main issues how I access the value of each folder. And then for each folder to access the images. Let's say I select the folder name "Toy story". Then I want all the images that are in the folder Toy Story. When I select the let's say the folder name "Brain", then I want every image that is in the folder "Brain". Help would be very much appreciated.
  11. Hi , I am pretty new to php. I would like to create a php website based on folders. I have a code so far that shows the names of folder in a selection box. What I would like to achieve now is how i get the images inside the folder after I click on submit. I know how to get the images with a glob function. What I don't know is how to get the value of each specific folder name. How would I do that? I have this code so far to get the names of the folders in the selection box: <form action="test.php" method="post"> <select name="myDirs"> <option value="" selected="selected">Select a genre</option> <?php $dirs = glob("*", GLOB_ONLYDIR); foreach($dirs as $val){ echo '<option value="'.$val.'">'.$val."</option>\n"; } ?> </select> <input type="submit" name="submit2"> <?php if (isset($_POST['submit2'])) foreach($dirs as $val){ { echo $val; } } ?> </form> How could get I'm now images which are in the folder of which folder names appear in the selection box?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.