title: Escape spaces in glob() in PHP?
body: <p>I have the following function in PHP, which is working great except for files with spaces in their names (<code>Good picture.jpg</code> for example).  Here it is:</p>
  
  <pre><code>function getphotolist($currentalbum) {
      $photos = glob($currentalbum.'/*.[Jj][Pp][Gg]');
      $albumparts = explode('_', $currentalbum);
      switch (array_key_exists(2,$albumparts)) {
          case false:
              usort($photos,"cmpexiftime");
              break;
          case true:
              usort($photos,"cmpexiftimer");
              break;
      }
      $photolist = "";
      foreach($photos as $photo){ 
          $phototitle = explode('_',basename($photo,".jpg"));
          $title = $phototitle[0];
          $thumb = $currentalbum.'/thumbs/'.basename($photo,".jpg").'_thumb.jpg';
          $exif = read_exif_data_raw("$photo",0);
          $desc = $exif["IFD0"]["ImageDescription"];
          $camera = ucwords(strtolower($exif["IFD0"]["Model"]));
          switch($exif["SubIFD"]["LensInfo"]) {
              case "105.0 mm f/2.8":
                  $lens = "AF-S Micro-Nikkor 105mm &amp;#402;/2.8 VR";
                  break;
              case "50.0 mm f/1.8":
                  if ($camera=="Nikon D700") {
                      $lens = "AF-S Nikkor 50mm &amp;#402;/1.8 G";
                  } else {
                      $lens = "AF Nikkor 50mm &amp;#402;/1.8 D";
                  }
                  break;
              case "18.0-55.0 mm f/3.5-5.6":
                  $lens = "AF-S Nikkor 18-55mm &amp;#402;/3.5-5.6 II";
                  break;
              default:
                  $lens = $exif["SubIFD"]["LensInfo"];
                  break;
          }
          $length = str_replace(" ","",$exif["SubIFD"]["FocalLength"]);
          $shutter = str_replace(" ","",str_replace("ec","",$exif["SubIFD"]["ShutterSpeedValue"]));
          $aperture = str_replace("f","&amp;#402;",$exif["SubIFD"]["ApertureValue"]);
          $iso = $exif["SubIFD"]["ISOSpeedRatings"];
          list($width,$height) = getimagesize($photo);
          if ($height==1080 &amp;&amp; $width==1920) {
              $photolist .= '&lt;span data-title="'.$title.'" data-thumb="'.$thumb.'" data-desc="'.$desc.'" data-camera="'.$camera.'" data-lens="'.$lens.'" data-length="'.$length.'" data-shutter="'.$shutter.'" data-aperture="'.$aperture.'" data-iso="'.$iso.'" style="background-image:url('.$photo.'); background-size:cover;" class="slide"&gt;&lt;/span&gt;';
          } elseif ($height &gt;= $width) {                            
              $photolist .= '&lt;span data-title="'.$title.'" data-thumb="'.$thumb.'" data-desc="'.$desc.'" data-camera="'.$camera.'" data-lens="'.$lens.'" data-length="'.$length.'" data-shutter="'.$shutter.'" data-aperture="'.$aperture.'" data-iso="'.$iso.'" style="background-image:url('.$photo.'); background-size:contain;" class="slide"&gt;&lt;/span&gt;';
          } else {
              $photolist .= '&lt;span data-title="'.$title.'" data-thumb="'.$thumb.'" data-desc="'.$desc.'" data-camera="'.$camera.'" data-lens="'.$lens.'" data-length="'.$length.'" data-shutter="'.$shutter.'" data-aperture="'.$aperture.'" data-iso="'.$iso.'" style="background-image:url('.$photo.'); background-size:contain;" class="slide"&gt;&lt;/span&gt;';
          }
      }
  return $photolist;
  }
  </code></pre>
  
  <p>Can anyone suggest how to fix this to work with files with spaces?  Thanks!</p>