title: Reload the page to get page source for error, dont know what is wrong
body: <p>Hi i am new to zend framework , i have created an app which will allow the user to edit an image and put some text inside the image, so i have decided to learn zend framework, by implementing personalmug application,</p>
  
  <p>I have uploaded the app to the hosted server subdomain, but for some reason my application is not working same like on localhost. on localhost it is working fine but on the hosted server i dont know what is worng, but there some questions about redirecting on localhost after ajax  success.</p>
  
  <p>The issues are given below.</p>
  
  <p>Question no 1.</p>
  
  <ol>
  <li>when i Open the home page and click the customize button it will display a model which contains a form, with four input fields, and when i type in the 4 lines and click the preview button, it will call controller personalmug and the action is preview, the preview action will create an image from existing image which is in public/img/ folder, now it is not creating the image to the folder public/img/image_uri and the responce is blank page, and in the firebug the html the message is "Reload the page to get the source". and when i reload the page the image is not there and the image is not in the public/img/image_uri folder on the hosted server, and the session is not created i think the preview action has some issues. but dont know where i am worng, i have tried to google it from 4 days but no success.</li>
  </ol>
  
  <p>The same thing is working on localhost.</p>
  
  <p>Question number 2</p>
  
  <ol>
  <li>i want to redirect the page after clicking the save button on preview.phtml page, now i have a save action in controller, which will save the data on localhost mysql database, and it is redirecting but only in the firbug , the actuall page is not redirecting, i have tried to use alerts in ajax success , but no use it is not displaying the message.</li>
  </ol>
  
  <p>Please help and Thanks in advance. i would appreciate my code corrections. and some code samples. thanks again.</p>
  
  <p>Index.phtml</p>
  
  <pre><code>    &lt;div class="row top-buffer"&gt;
      &lt;div class="span9"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-4"&gt;&lt;img src='&lt;?php echo $this-&gt;basePath('img/whitemug toxic fox.jpg') ?&gt;'class="img-responsive"/&gt;&lt;/div&gt;
              &lt;div class="col-md-6"&gt;
                  &lt;h3&gt;&lt;strong&gt;Personal Mug&lt;/strong&gt;&lt;/h3&gt;
                  &lt;h3&gt;&lt;small&gt;Show your amazing coach just how great he is with this No.1 Coach Mug. This mug is a great gift for any occasion, make your gift extra special by personalising it with any name of your choice. This thoughtful gift is guaranteed to impress!&lt;/small&gt;&lt;/h3&gt;
                  &lt;a name="fulldescription"&gt;Read Full Description&lt;/a&gt;
                  &lt;div class="row top-buffer"&gt;
                      &lt;div class="col-md-8"&gt;
                          &lt;button class="btn btn-success btn-lg btn-block" data-toggle="modal" data-target="#myModal"&gt;Customize&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row top-buffer"&gt;
                      &lt;ul&gt;
                          &lt;li&gt;
                              The mug has space for a maximum of 48 characters, over a maximum of 4 lines.
                          &lt;/li&gt;
                          &lt;li&gt;
                              Free Delivery when you spend over £40
                          &lt;/li&gt;
                          &lt;li&gt;
                              Guaranteed Fast, Secure Shipping
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-md-6 "&gt;
          &lt;h3&gt;&lt;strong&gt;Personal Mug&lt;/strong&gt;&lt;/h3&gt;
          &lt;h4&gt;&lt;small&gt;Is your coach simply the best?&lt;/small&gt;&lt;/h4&gt;
          &lt;h4&gt;Reward them with this amazing No.1 Coach Mug. This mug features a fabulous award design with the message COACH (any name) no.1! Make this thoughtful gift extra special and personal by adding your coaches name!&lt;/h4&gt;
  
      &lt;/div&gt;
  
      &lt;div class="col-md-6 "&gt;
          &lt;?php foreach($personalmugs as $personalmug) : ?&gt;
          &lt;div class="col-md-3 top-buffer"&gt; &lt;a href="#"&gt;
                  &lt;img src="&lt;?php echo $this-&gt;basePath($this-&gt;escapeHtml($personalmug-&gt;image_uri)); ?&gt;"  class="img-thumbnail img-responsive"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
          &lt;?php endforeach; ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Modal --&gt;
  &lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;span class="sr-only"&gt;Close&lt;/span&gt;&lt;/button&gt;
                  &lt;h4 class="modal-title" id="myModalLabel"&gt;Submit text&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;form class="form-horizontal" action="personal-mug/preview" role="form" method="POST"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label for="inputText" class="col-sm-2 control-label"&gt;Text&lt;/label&gt;
                          &lt;div class="col-sm-10"&gt;
                              &lt;input class="form-control" type="text" name="mugtext1" maxlength="12" placeholder=Line1 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required&gt;
                              &lt;input class="form-control" type="text" name="mugtext2" maxlength="12" placeholder=Line2 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required&gt;
                              &lt;input class="form-control" type="text" name="mugtext3" maxlength="12" placeholder=Line3 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required&gt;
                              &lt;input class="form-control" type="text" name="mugtext4" maxlength="12" placeholder=Line4 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required&gt;
  
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;div class="col-sm-offset-2 col-sm-10"&gt;
                              &lt;button name="submit" value="submit" type="submit" class="btn btn-default"&gt;Preview&lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The preview phtml file code.</p>
  
  <pre><code>&lt;div class="row top-buffer"&gt;
      &lt;div class="span9"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-4"&gt;&lt;img id="mug1" name="mug1" src='
                  &lt;?php 
                  if(isset($_SESSION['preview_image_id']) &amp;&amp; !empty($_SESSION['preview_image_id'])){
                      $ID = $_SESSION['preview_image_id'];
                      echo $this-&gt;basePath("img/image_uri/$ID.jpg");
                  } ?&gt;'class="img-responsive"/&gt;&lt;/div&gt;
              &lt;div class="col-md-6"&gt;
                  &lt;h3&gt;&lt;strong&gt;Personal Mug&lt;/strong&gt;&lt;/h3&gt;
                  &lt;h3&gt;&lt;small&gt;Show your amazing coach just how great he is with this No.1 Coach Mug. This mug is a great gift for any occasion, make your gift extra special by personalising it with any name of your choice. This thoughtful gift is guaranteed to impress!&lt;/small&gt;&lt;/h3&gt;
  
                  &lt;div class="row top-buffer"&gt;
                      &lt;div class="col-md-8"&gt;
  
                          &lt;a id ="buttonSave" class="btn btn-success btn-lg btn-block"&gt;Save&lt;/a&gt;
                          &lt;a class="btn btn-success btn-lg btn-block" href="&lt;?php echo $this-&gt;url('personal-mug', array('action'=&gt;'add'));?&gt;"&gt;Edit&lt;/a&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row top-buffer"&gt;
                      &lt;ul&gt;
                          &lt;li&gt;
                              The mug has space for a maximum of 48 characters, over a maximum of 4 lines.
                          &lt;/li&gt;
                          &lt;li&gt;
                              Free Delivery when you spend over £40
                          &lt;/li&gt;
                          &lt;li&gt;
                              Guaranteed Fast, Secure Shipping
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;script&gt;
      $('#buttonSave').click(function (){
              var image_uri = $("#mug1").attr("src");
              $.ajax({
                      type: 'POST',
                      dataType: 'json',
                      url: 'http://toxicfox.com/personal-mug/add',
                      async: false,
  
                      // you can use an object here
                      data: { image_uri: image_uri},
                      success: function(json) {
                          console.log(json.image_uri);
                      }
                  });
              // you might need to do this, to prevent anchors from following
              // or form controls from submitting
  
          });
  &lt;/script&gt;
  </code></pre>
  
  <p>The controller.</p>
  
  <pre><code>namespace PersonalMug\Controller;
  
  use Zend\Mvc\Controller\AbstractActionController;
  use Zend\View\Model\ViewModel;
  use PersonalMug\Model\PersonalMug;          
  use PersonalMug\Form\PersonalMugForm;    
  
  
  class PersonalMugController extends AbstractActionController{
  protected $personalmugTable;
  
  public function getPersonalMugTable(){
      if(!$this-&gt;personalmugTable){
          $sm = $this-&gt;getServiceLocator();
          $this-&gt;personalmugTable = $sm-&gt;get('PersonalMug\Model\PersonalMugTable');
      }
      return $this-&gt;personalmugTable;
  }
  
  public function indexAction(){
      return new ViewModel(
          array(
              'personalmugs' =&gt; $this-&gt;getPersonalMugTable()-&gt;fetchAll(),
          ));
  }
  public function addAction(){    
  
      $data['image_uri'] =  $this-&gt;getRequest()-&gt;getPost('image_uri');
      $personalmug = new PersonalMug();
      $personalmug-&gt;exchangeArray($data);
      $this-&gt;getPersonalMugTable()-&gt;save($personalmug);
      return $this-&gt;redirect()-&gt;toRoute('personal-mug');
  }
  public function previewAction(){
      if(isset($_POST['submit'])){
          session_start();
          $ID = uniqid();
          $_SESSION['preview_image_id'] = $ID;
          $text1 = htmlspecialchars($_POST['mugtext1']);
          $text2 = htmlspecialchars($_POST['mugtext2']);
          $text3 = htmlspecialchars($_POST['mugtext3']);
          $text4 = htmlspecialchars($_POST['mugtext4']);
          $this-&gt;getPersonalMugTable()-&gt;preview($ID,$text1,$text2,$text3,$text4);
      }
  }
  </code></pre>
  
  <p>The personalmug table file.</p>
  
  <pre><code>namespace PersonalMug\Model;
  
  use Zend\Db\TableGateway\TableGateway;
  use Zned\ServerUrl\Helper;
  
  class PersonalMugTable{
      protected $tableGateway;
  
      public function __construct(TableGateway $tableGateway){
          $this-&gt;tableGateway = $tableGateway;
      }
  
      public function fetchAll(){
          $resultSet = $this-&gt;tableGateway-&gt;select();
          return $resultSet;
      }
  
      public function getImage($image_id){
          $image_id  = (int) $image_id;
          $rowset = $this-&gt;tableGateway-&gt;select(array('image_id' =&gt; $image_id));
          $row = $rowset-&gt;current();
          if(!$row){
              throw new \Exception("Could not find row $image_id");
          }
          return $row;
      }
  
      public function save(PersonalMug $personalmug){
          $data = array(
              'image_id'  =&gt; $personalmug-&gt;image_id,
              'image_uri'  =&gt; $personalmug-&gt;image_uri,
          );
  
          $image_id = (int) $personalmug-&gt;image_id;
          if($image_id == 0){
              $this-&gt;tableGateway-&gt;insert($data);
          }else{
              if($this-&gt;getImage($image_id)){
                  $this-&gt;tableGateway-&gt;update($data, array('image_id' =&gt; $image_id));
              }else{
                  throw new \Exception('Mug id does not exist');
              }
          }
      }
  
      public function deleteAlbum($image_id){
          $this-&gt;tableGateway-&gt;delete(array('image_id' =&gt; (int) $image_id));
      }
  
      public function preview($ID,$text1,$text2,$text3,$text4){
          strtoupper($text1);
          strtoupper($text2);
          strtoupper($text3);
          strtoupper($text4);
          // load the image from the file specified:
  
          $im = imagecreatefromjpeg('public/img/whitemug%20toxic%20fox.jpg');
          // if there's an error, stop processing the page:
          if(!$im){
              die("");
          }
  
          // define some colours to use with the image
          $black = imagecolorallocate($im, 0, 0, 0);
  
  
          // now we want to write in the centre of the rectangle:
          $font ="public/fonts/arial.ttf"; // store the int ID of the system font we're using in $font
          // store the text we're going to write in $text
  
          // finally, write the string:
  
          imagettftext($im,60,0,260,460,$black,$font,$text1);
          imagettftext($im,60,0,260,560,$black,$font,$text2);
          imagettftext($im,60,0,260,660,$black,$font,$text3);
          imagettftext($im,60,0,260,760,$black,$font,$text4);
  
          imagejpeg($im, "public/img/image_uri/$ID.jpg");
  
          // tidy up
          imagedestroy($im);
      }
  }
  </code></pre>