unable to read images inside folder using php within javascript












0















I have a folder and every 10mins images will downloaded from server to a specific folder into my local server and then I have a script that reads the images after images are being downloaded, but unfortunately its not working.



I used ajax to php file to download images from server, here is the code inside php file:



while($row = $query->fetch_assoc()) {
$image_name = 'ads-id-'.$row['id'].'.gif';
$image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
}


after ajax success it execute this code to read images:



var output  =   '<?php $dirname = "assets/ads/"; ?>'
output += '<?php $images = glob($dirname."*.gif"); ?>'
output += '<?php foreach($images as $image) { ?>'
output += '<?php echo '<div class="col-md-12">'; ?>'
output += '<?php echo '<div class="card" style="border: 0px;">'; ?>'
output += '<?php echo '<img class="card-img-top" src="'.$image.'" alt="ads" /><br />'; ?>'
output += '<?php echo '</div>'; ?>'
output += '<?php echo '</div>'; ?>'
output += '<?php } ?>';
$('.sl-ads-holder').append(output);









share|improve this question



























    0















    I have a folder and every 10mins images will downloaded from server to a specific folder into my local server and then I have a script that reads the images after images are being downloaded, but unfortunately its not working.



    I used ajax to php file to download images from server, here is the code inside php file:



    while($row = $query->fetch_assoc()) {
    $image_name = 'ads-id-'.$row['id'].'.gif';
    $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
    file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
    }


    after ajax success it execute this code to read images:



    var output  =   '<?php $dirname = "assets/ads/"; ?>'
    output += '<?php $images = glob($dirname."*.gif"); ?>'
    output += '<?php foreach($images as $image) { ?>'
    output += '<?php echo '<div class="col-md-12">'; ?>'
    output += '<?php echo '<div class="card" style="border: 0px;">'; ?>'
    output += '<?php echo '<img class="card-img-top" src="'.$image.'" alt="ads" /><br />'; ?>'
    output += '<?php echo '</div>'; ?>'
    output += '<?php echo '</div>'; ?>'
    output += '<?php } ?>';
    $('.sl-ads-holder').append(output);









    share|improve this question

























      0












      0








      0








      I have a folder and every 10mins images will downloaded from server to a specific folder into my local server and then I have a script that reads the images after images are being downloaded, but unfortunately its not working.



      I used ajax to php file to download images from server, here is the code inside php file:



      while($row = $query->fetch_assoc()) {
      $image_name = 'ads-id-'.$row['id'].'.gif';
      $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
      file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
      }


      after ajax success it execute this code to read images:



      var output  =   '<?php $dirname = "assets/ads/"; ?>'
      output += '<?php $images = glob($dirname."*.gif"); ?>'
      output += '<?php foreach($images as $image) { ?>'
      output += '<?php echo '<div class="col-md-12">'; ?>'
      output += '<?php echo '<div class="card" style="border: 0px;">'; ?>'
      output += '<?php echo '<img class="card-img-top" src="'.$image.'" alt="ads" /><br />'; ?>'
      output += '<?php echo '</div>'; ?>'
      output += '<?php echo '</div>'; ?>'
      output += '<?php } ?>';
      $('.sl-ads-holder').append(output);









      share|improve this question














      I have a folder and every 10mins images will downloaded from server to a specific folder into my local server and then I have a script that reads the images after images are being downloaded, but unfortunately its not working.



      I used ajax to php file to download images from server, here is the code inside php file:



      while($row = $query->fetch_assoc()) {
      $image_name = 'ads-id-'.$row['id'].'.gif';
      $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
      file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
      }


      after ajax success it execute this code to read images:



      var output  =   '<?php $dirname = "assets/ads/"; ?>'
      output += '<?php $images = glob($dirname."*.gif"); ?>'
      output += '<?php foreach($images as $image) { ?>'
      output += '<?php echo '<div class="col-md-12">'; ?>'
      output += '<?php echo '<div class="card" style="border: 0px;">'; ?>'
      output += '<?php echo '<img class="card-img-top" src="'.$image.'" alt="ads" /><br />'; ?>'
      output += '<?php echo '</div>'; ?>'
      output += '<?php echo '</div>'; ?>'
      output += '<?php } ?>';
      $('.sl-ads-holder').append(output);






      javascript php ajax






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 3:15









      Qatest123Qatest123

      11




      11
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You want to do the php part on the php side, you are incorrectly mixing PHP and JavaScript.



          First, do the php that you already have, then you want to run the other script as well on this page, after the first.



             while($row = $query->fetch_assoc()) {
          $image_name = 'ads-id-'.$row['id'].'.gif';
          $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
          file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
          }

          $dirname = "assets/ads/";
          $images = glob($dirname."*.gif");

          foreach($images as $image): ?>

          <div class="col-md-12">
          <div class="card" style="border: 0px;">
          <img class="card-img-top" src="<?php echo $image ?>" alt="ads" /><br />
          </div>
          </div>

          <?php endforeach ?>


          On your ajax, you then will have the returned data as html that you can append:



          success: function(response) {
          $('.sl-ads-holder').append(response);
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423364%2funable-to-read-images-inside-folder-using-php-within-javascript%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You want to do the php part on the php side, you are incorrectly mixing PHP and JavaScript.



            First, do the php that you already have, then you want to run the other script as well on this page, after the first.



               while($row = $query->fetch_assoc()) {
            $image_name = 'ads-id-'.$row['id'].'.gif';
            $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
            file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
            }

            $dirname = "assets/ads/";
            $images = glob($dirname."*.gif");

            foreach($images as $image): ?>

            <div class="col-md-12">
            <div class="card" style="border: 0px;">
            <img class="card-img-top" src="<?php echo $image ?>" alt="ads" /><br />
            </div>
            </div>

            <?php endforeach ?>


            On your ajax, you then will have the returned data as html that you can append:



            success: function(response) {
            $('.sl-ads-holder').append(response);
            }





            share|improve this answer




























              0














              You want to do the php part on the php side, you are incorrectly mixing PHP and JavaScript.



              First, do the php that you already have, then you want to run the other script as well on this page, after the first.



                 while($row = $query->fetch_assoc()) {
              $image_name = 'ads-id-'.$row['id'].'.gif';
              $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
              file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
              }

              $dirname = "assets/ads/";
              $images = glob($dirname."*.gif");

              foreach($images as $image): ?>

              <div class="col-md-12">
              <div class="card" style="border: 0px;">
              <img class="card-img-top" src="<?php echo $image ?>" alt="ads" /><br />
              </div>
              </div>

              <?php endforeach ?>


              On your ajax, you then will have the returned data as html that you can append:



              success: function(response) {
              $('.sl-ads-holder').append(response);
              }





              share|improve this answer


























                0












                0








                0







                You want to do the php part on the php side, you are incorrectly mixing PHP and JavaScript.



                First, do the php that you already have, then you want to run the other script as well on this page, after the first.



                   while($row = $query->fetch_assoc()) {
                $image_name = 'ads-id-'.$row['id'].'.gif';
                $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
                file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
                }

                $dirname = "assets/ads/";
                $images = glob($dirname."*.gif");

                foreach($images as $image): ?>

                <div class="col-md-12">
                <div class="card" style="border: 0px;">
                <img class="card-img-top" src="<?php echo $image ?>" alt="ads" /><br />
                </div>
                </div>

                <?php endforeach ?>


                On your ajax, you then will have the returned data as html that you can append:



                success: function(response) {
                $('.sl-ads-holder').append(response);
                }





                share|improve this answer













                You want to do the php part on the php side, you are incorrectly mixing PHP and JavaScript.



                First, do the php that you already have, then you want to run the other script as well on this page, after the first.



                   while($row = $query->fetch_assoc()) {
                $image_name = 'ads-id-'.$row['id'].'.gif';
                $image_url = 'http://dev.websiteprojectupdates.com/axul-display/assets/ads/'.$image_name;
                file_put_contents('assets/ads/'.$image_name, file_get_contents($image_url));
                }

                $dirname = "assets/ads/";
                $images = glob($dirname."*.gif");

                foreach($images as $image): ?>

                <div class="col-md-12">
                <div class="card" style="border: 0px;">
                <img class="card-img-top" src="<?php echo $image ?>" alt="ads" /><br />
                </div>
                </div>

                <?php endforeach ?>


                On your ajax, you then will have the returned data as html that you can append:



                success: function(response) {
                $('.sl-ads-holder').append(response);
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 21:48









                RasclattRasclatt

                11.2k31628




                11.2k31628
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423364%2funable-to-read-images-inside-folder-using-php-within-javascript%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini