WordPress.org

Ready to get started?Download WordPress

Forums

Grab some image URLs from a folder on my server and display them (2 posts)

  1. ldexterldesign
    Member
    Posted 5 years ago #

    Basically just got some massive issues with using getcwd() I think. I need to grab some image URLs from a folder on my server and display them.

    Working:

    <?php
    <strong>  // get current working directory
      $cwd = getcwd();
      $dir = $cwd . '/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff';</strong>
      // get file names from logos directory
      $files = scandir($dir);
      // count total files in directory
      $totalFiles = count($files) - 1;
      // loop through file names and output the images
      for ($i = 1; $i <= $totalFiles; $i++) {
          $filepath = $dir . "/" . $files[$i];
          echo '<img src="' . $filepath . '" />';
      }
    ?>

    Outputs:
    <img src="<strong>C:\xampp\htdocs\wordpress/wp-content/themes/ldexterldesign</strong>/images/logos/accreditors/hoverOff/ABBE.gif" />

    Not working:

    <?php
    <strong>  // get current working directory
      $cwd = get_bloginfo('stylesheet_directory');
      $dir = $cwd . '/images/logos/accreditors/hoverOff';</strong>
      // get file names from logos directory
      $files = scandir($dir);
      // count total files in directory
      $totalFiles = count($files) - 1;
      // loop through file names and output the images
      for ($i = 1; $i <= $totalFiles; $i++) {
          $filepath = $dir . "/" . $files[$i];
          echo '<img src="' . $filepath . '" />';
      }
    ?>

    Outputs:
    The correct HTML, but throws a PHP error? Obviously cause it can't find the files on my localhost.

    Thoroughly lost now :[ Is there some etiquette to using getcwd() when developing locally?

    Thanks,
    L

  2. ldexterldesign
    Member
    Posted 5 years ago #

    Yea, basically just need to know how to use getcwd() when working on a development server. It keeps looking in my C: drive instead of my localhost.

    It'll save me hard coding a URL in there, which isn't ideal at all.

    Any help would really get me out of a bind here.

    Thanks,
    L

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags