Jump to content

chrathan

New Members
  • Posts

    5
  • Joined

  • Last visited

chrathan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks Ch0cu3r , it was something I was not aware of.
  2. I tried to use: if($_SERVER['REQUEST_METHOD'] == 'POST'){ action($image); } Before html form, the results was as in the case I place my function inside <input type="submit" value="submit" /> . It store my choice with the next image in listfile neglecting the first image.
  3. Can I add the code in a new php file using the following: if(isset($_POST['submit'])) { display(); //function action }
  4. I understand the problem, I am not sure if I understand the solution. I am not that familiar with php, so is it possible to clarify your answer?
  5. I am reading images from the directory 'images' which contains several folders with images. I want to show every image in a div and with the checkbox to decide if it is fashion or not fashion. I am using the following code in order to read files from directory and showing them in browser. The divs is one after other: <?php function listFolderFiles($dir){ $html = ''; // Init the session if it did not start yet if(session_id() == '') session_start(); $html .= '<ol>'; foreach(new DirectoryIterator($dir) as $folder){ if(!$folder->isDot()){ if($folder->isDir()){ // $html .= '<li>'; $user = $dir . '/' . $folder; foreach (new DirectoryIterator($user) as $file) { if($file != '.' && $file != '..'){ $image = $user . '/' . $file; // Check the pictures URLs in the session if(isset($_SESSION['pictures']) && is_array($_SESSION['pictures'])){ // Check if this image was already served if(in_array($image, $_SESSION['pictures'])){ // Skip this image continue; } } else { // Create the session variable $_SESSION['pictures'] = array(); } // Add this image URL to the session $_SESSION['pictures'][] = $image; // Build the form //echo $image, "</br>"; $html .= ' <style> form{ font-size: 150%; font-family: "Courier New", Monospace; display: inline-block; align: middle; text-align: center; font-weight: bold; } </style> <form class = "form" action="' . action($image) . '" method="post"> <div> <img src="' . $image . '" alt="" /> </div> <label for="C1">FASHION</label> <input id="fashion" type="radio" name="fashion" id="C1" value="fashion" /> <label for="C2"> NON FASHION </label> <input id="nfashion" type="radio" name="nfashion" id="C2" value="nfashion" /> <input type="submit" value="submit" /> </form>'; // Show one image at a time // Break the loop break 2; } } // $html .= '</li>'; } } } $html .= '</ol>'; return $html; } //##### Action function function action($img){ $myfile = fopen("annotation.txt", "a"); if (isset($_POST['fashion'])) { fwrite($myfile, $img." -- fashion\n"); // echo '<br />' . 'fashion image'; } else{ fwrite($myfile, $img." -- nonFashion\n"); // echo '<br />' . ' The submit button was pressed<br />'; } } echo listFolderFiles('images//'); ?> When I make call of action($image) from inside form tag, I noticed, that a default value of submit it is parsed to the function, thus it stores the name of the image with the default value and the chosen value for the first image it is parsed to the second image, the chosen value of the second image it is stored to the file with the third image and so on. When I make call in side input submit tag it began storing to the file from the second image with the value of the first one and so on. I couldn't manage to have stored to the file the correct correspondence between the image and the chosen value. Where should I make call of the action function in order to do it properly?
×
×
  • 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.