title: php get all files from a remote directory
body: <p>I have searched, and searched for 3+ hours this morning and tried over 10 different setups for how to grab and display a list of images from a url, and none of them worked correctly. I would either end up with no info displaying, or a 500 error. Can someone point me to an example or help me out here on how to do this properly. file_get_contents is not a viable option.</p>
  
  <p>Example Directory: <a href="http://www.webtoonlive.com/webtoon/fantasy_world_survival/ch02/" rel="nofollow">http://www.webtoonlive.com/webtoon/fantasy_world_survival/ch02/</a></p>
  
  <p>Files i know that are in that directory:
  001.jpg,
  002.jpg,
  003.jpg</p>
  
  <p>I would like the output to be the exact url to the file.</p>
  
  <p>Let me know if more info is needed, i'm not 100% sure exactly how to explain it right lol.</p>
  
  <p>Edit: </p>
  
  <p>ok so what I guess i actually want to do is check the url for all the image tags and display a list with the full url to that image.</p>
  
  <p>New to working with this url+images+php stuff so please don't hit me too hard with your downvote hammer with no comments lol.</p>
  
  <p>Code I Tried:</p>
  
  <pre><code>&lt;?php
  /*
  Credits: Bit Repository
  URL: http://www.bitrepository.com/
  */
  
  $url = $location;
  
  // Fetch page
  $string = FetchPage($url);
  
  // Regex that extracts the images (full tag)
  $image_regex_src_url = '/&lt;img[^&gt;]*'.
  
  'src=[\"|\'](.*)[\"|\']/Ui';
  
  preg_match_all($image_regex, $string, $out, PREG_PATTERN_ORDER);
  
  $img_tag_array = $out[0];
  
  echo "&lt;pre&gt;"; print_r($img_tag_array); echo "&lt;/pre&gt;";
  
  // Regex for SRC Value
  $image_regex_src_url = '/&lt;img[^&gt;]*'.
  
  'src=[\"|\'](.*)[\"|\']/Ui';
  
  preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER);
  
  $images_url_array = $out[1];
  
  echo "&lt;pre&gt;"; print_r($images_url_array); echo "&lt;/pre&gt;";
  
  // Fetch Page Function
  
  function FetchPage($path)
  {
  $file = fopen($path, "r"); 
  
  if (!$file)
  {
  exit("The was a connection error!");
  } 
  
  $data = '';
  
  while (!feof($file))
  {
  // Extract the data from the file / url
  
  $data .= fgets($file, 1024);
  }
  return $data;
  }
  ?&gt;
  </code></pre>
  
  <p>and it returned a blank page</p>