title: Google App Engine: How to serve uploaded images in a PHP loop from google cloud storage
body: <p>I have been using PHP Codeigniter Framework hosted on Google App Engine Platform.</p>
  
  <p>As we know due to security reason Google does not allow to upload images as same as general platform. So I used Google Cloud Storage to upload images and I have successfully implemented it by creating a septate library in Codeigniter.</p>
  
  <p>Problem I am having is how to server them in a foreach or for loop. If I call image once than it displayed on the web page but if I tries to implement that code in a loop it halts when loop counter goes to second count. Below is the library and Helper function I created and calling in a loop.</p>
  
  <p><strong>Library:</strong></p>
  
  <pre><code>    &lt;?php
  defined('BASEPATH') OR exit('No direct script access allowed');
  use google\appengine\api\cloud_storage\CloudStorageTools;
  
  class Display {
  
      var $config = Array();
      var $image_url = '';
      var $folder = '';
      var $image  = '';
      var $size   = 400;
      var $crop = true;
  
      public function __construct(){
          $bucket = CloudStorageTools::getDefaultGoogleStorageBucketName();
          $this-&gt;image_url = 'gs://' . $bucket . '/uploads/';
      }
  
      public function image_url(){
          $path = $this-&gt;image_url.$this-&gt;folder.'/';
          $this-&gt;image_url  = ( !empty($this-&gt;image) &amp;&amp;  is_file( $path . $this-&gt;image)) ?$path .$this-&gt;image:'noimage_thb.png' ;
          $image_url = @CloudStorageTools::getImageServingUrl($this-&gt;image_url);
          /*printArray($this-&gt;image_url,1);*/
          if($image_url == ''){
              $image_url = '';
          }
  
          return $image_url;
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>Helper Function:</strong></p>
  
  <pre><code>if (!function_exists('image_url')) {
      function image_url($folderName,$image, $size, $crop = false)
      {
          $CI =&amp; get_instance();
          // we first load the upload library
          $CI-&gt;load-&gt;library('display');
          $CI-&gt;display-&gt;folder = $folderName;
          $CI-&gt;display-&gt;image = $image;
          $CI-&gt;display-&gt;size = $size;
          $CI-&gt;display-&gt;crop = $crop;
          $url = $CI-&gt;display-&gt;image_url();
          return $url;
      }
  }
  </code></pre>
  
  <p><strong>View File Code(Loop):</strong></p>
  
  <pre><code>&lt;div class="fotorama" data-allowfullscreen="true" data-nav="thumbs"&gt;
      &lt;?php
              $images = explode(",", $dbdata['beach_photo']);
              for ($img_no = 0; $img_no &lt; count($images); $img_no++) {
                  $imageUrl = image_url('venue', $images[$img_no], '400');
      ?&gt;
       &lt;img src="&lt;?php echo $imageUrl; ?&gt;" class="img-responsive"/&gt;
   &lt;?php } ?&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p><strong><em>Please leave your answers if anyone faced same issue.</em></strong></p>