0

Hi! my first time here. i'm new to programming. I have a code which checks if a .txt and .jpg file exist in the same folder.(this part is working well) after checking it needs to display the value of .txt file and the .jpg file inside a modal popup. (in my code i tried using an alert box, but as i said it needs to be a modal pop up) i tried echoing the function for modal popup but it displays the code instead of the image. i also want to format the modal popup where the .jpg displays on the left side and the .txt value is on the right. hope you can help me with this. Thanks a lot in advance! here's my code:

index.php

 <script>
            function readexisting() {
                 jQuery.ajax({
                    type: "POST",
                    url: 'controller.php',
                    data: {action: 'readexisting', arguments: 'your data'}, 
                    success:function(data) {
                                         data = data.split("~:~");
                                         alert(data[0]); // message
                                         //alert(data[1]); // content
                    }
                });
            }
        </script>



controller.php

<?php
    include_once("model.php");

    $obj = new Model();

    switch($_POST["action"]){ 
        case 'readexisting': 
            $obj->readexisting();
        break;      
    } 
?>



execute.php
<style type="text/CSS">
    #overlay {
     display: block;
     position: absolute;
     left: 0px;
     top: 0px;
     width:100%;
     height:100%;
     text-align:center;
     z-index: 1500;
     visibility:hidden;
     /*background-image:url(ThankYou.png);*/
        }
    #overlay div {
     width:800px;
     margin: 100px auto;
     background-color: none;/*rgba(255, 255, 255, 0.9)*/
     border:none;
     padding:15px;
     text-align:center;
    }
    </style>


    <script type="text/javascript">
    function overlay() {
el = document.getElementById("overlay");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
    }
 </script>   
 </head>
 <body>

 <div id="overlay">
     <div>
          <img src="events/event-01.jpg" alt="module" style="width:230px; height:313px;">
          <p><a href='#close' onclick='overlay()'><img src="images/close_btn.png" alt="module" style="width:15px; height:15px; position:relative; margin-left: 380px; top: -317px;"></a></p>
     </div>

   </body>
</html>
        <?php
        class Model {


           public function readexisting() {
               if (file_exists($_SERVER['DOCUMENT_ROOT']."/Project/events/folder-01/event-01.txt") && file_exists($_SERVER['DOCUMENT_ROOT']."/Project/events/folder-01/event-01.jpg")) {  
                    echo "<script>";
                     echo "overlay();";
                     echo "</script>";

                    $myFile = ($_SERVER['DOCUMENT_ROOT']."/Project/events/folder-01/event-01.txt");
                    $fh = fopen($myFile, 'r');
                    $theData = fread($fh, filesize($myFile));
                    fclose($fh);
                    echo $theData;                       
               } 
               else {
                    echo "The file $myFile does not exist";
               }
           }

        }
        ?>
2
Contributors
1
Reply
21
Views
3 Years
Discussion Span
Last Post by LastMitch
0

I have a code which checks if a .txt and .jpg file exist in the same folder.(this part is working well) after checking it needs to display the value of .txt file and the .jpg file inside a modal popup. (in my code i tried using an alert box, but as i said it needs to be a modal pop up) i tried echoing the function for modal popup but it displays the code instead of the image. i also want to format the modal popup where the .jpg displays on the left side and the .txt value is on the right. hope you can help me with this.

@karen.frias0316

If you want an image or text to appear on the popup. Then it's a path issue. I assume you the image nor text are not from the database, then it shouldn't be an issue.

If the image or text is from the database and you trying to echo the info, then you are missing a very important code. It's call sessions.

I always include sessions on every pop-window so I can echo out data from the database, that's only from php without ajax/javascript.

Since you are using javascript/ajax, it's a different approached. It's the path to the file.

You combining 2 languages, so base on the code you provided, it's from the php code not the javascript.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.