title: how to export images to excel in php?
body: <p>I am using the code below. It is working fine for <code>localhost</code> but it's not working for live. I am getting an error like below:</p>
  
  <blockquote>
    <p>This site can’t be reached</p>
    
    <p>The webpage at <a href="http://e2dshop.com/phpexcel_gd/direct.php" rel="nofollow noreferrer">http://e2dshop.com/phpexcel_gd/direct.php</a> might be temporarily down or it may have moved permanently to a new web address.
    ERR_INVALID_RESPONSE</p>
  </blockquote>
  
  <pre><code>&lt;?php
  
  function my_constants(){
      $url = 'http://' . $_SERVER['HTTP_HOST'] . "/phpexcel_gd/";
      $path = $_SERVER['DOCUMENT_ROOT'] . '/phpexcel_gd/';
      define('SITEURL', $url);
      define('SITEPATH', str_replace('\\', '/', $path));
  }
  
  function report_details($display = null) {
  
      if($display){
          $imagePath = SITEURL . "images/";
      } else {
          $imagePath = SITEPATH . "images/";
      }   
  
      $reportdetails = array(
          array('BrandIcon' =&gt; $imagePath . "facebook.png",'Comapany' =&gt; "facebook",'Rank' =&gt; "2",'Link' =&gt; "http://www.facebook.com"),
          array('BrandIcon' =&gt; $imagePath . "googleplus.png",'Comapany' =&gt; "googleplus",'Rank' =&gt; "1",'Link' =&gt; "http://www.googleplus.com"),
          array('BrandIcon' =&gt; $imagePath . "twitter.png",'Comapany' =&gt; "twitter",'Rank' =&gt; "3",'Link' =&gt; "http://www.twitter.com"),
          array('BrandIcon' =&gt; $imagePath . "linkedin.png",'Comapany' =&gt; "linkedin",'Rank' =&gt; "8",'Link' =&gt; "http://www.linkedin.com"),
      );
      return $reportdetails;
  
  }
  /**
  * Create excel by from direct request
  */
  function xlscreation_direct() {
  
      $reportdetails = report_details();
  
      require_once SITEPATH . 'PHPExcel/Classes/PHPExcel.php';
  
      $objPHPExcel = new PHPExcel(); 
      $objPHPExcel-&gt;getProperties()
              -&gt;setCreator("user")
              -&gt;setLastModifiedBy("user")
              -&gt;setTitle("Office 2007 XLSX Test Document")
              -&gt;setSubject("Office 2007 XLSX Test Document")
              -&gt;setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
              -&gt;setKeywords("office 2007 openxml php")
              -&gt;setCategory("Test result file");
  
      // Set the active Excel worksheet to sheet 0
      $objPHPExcel-&gt;setActiveSheetIndex(0); 
  
      // Initialise the Excel row number
      $rowCount = 0; 
  
      // Sheet cells
      $cell_definition = array(
          'A' =&gt; 'BrandIcon',
          'B' =&gt; 'Comapany',
          'C' =&gt; 'Rank',
          'D' =&gt; 'Link'
      );
  
      // Build headers
      foreach( $cell_definition as $column =&gt; $value )
      {
          $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension("{$column}")-&gt;setAutoSize(true);
          $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue( "{$column}1", $value ); 
      }
  
      // Build cells
      while( $rowCount &lt; count($reportdetails) ){ 
          $cell = $rowCount + 2;
          foreach( $cell_definition as $column =&gt; $value ) {
  
              $objPHPExcel-&gt;getActiveSheet()-&gt;getRowDimension($rowCount + 2)-&gt;setRowHeight(35); 
  
              switch ($value) {
                  case 'BrandIcon':
                      if (file_exists($reportdetails[$rowCount][$value])) {
                          $objDrawing = new PHPExcel_Worksheet_Drawing();
                          $objDrawing-&gt;setName('Customer Signature');
                          $objDrawing-&gt;setDescription('Customer Signature');
                          //Path to signature .jpg file
                          $signature = $reportdetails[$rowCount][$value];    
                          $objDrawing-&gt;setPath($signature);
                          $objDrawing-&gt;setOffsetX(25);                     //setOffsetX works properly
                          $objDrawing-&gt;setOffsetY(10);                     //setOffsetY works properly
                          $objDrawing-&gt;setCoordinates($column.$cell);             //set image to cell 
                          $objDrawing-&gt;setWidth(32);  
                          $objDrawing-&gt;setHeight(32);                     //signature height  
                          $objDrawing-&gt;setWorksheet($objPHPExcel-&gt;getActiveSheet());  //save 
                      } else {
                          $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($column.$cell, "Image not found" ); 
                      }
                      break;
                  case 'Link':
                      //set the value of the cell
                      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue($column.$cell, $reportdetails[$rowCount][$value]);
                      //change the data type of the cell
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($column.$cell)-&gt;setDataType(PHPExcel_Cell_DataType::TYPE_STRING2);
                      ///now set the link
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($column.$cell)-&gt;getHyperlink()-&gt;setUrl(strip_tags($reportdetails[$rowCount][$value]));
                      break;
  
                  default:
                      $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($column.$cell, $reportdetails[$rowCount][$value] ); 
                      break;
              }
  
          }
  
          $rowCount++; 
      } 
  
      $rand = rand(1234, 9898);
      $presentDate = date('YmdHis');
      $fileName = "report_" . $rand . "_" . $presentDate . ".xlsx";
  
      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
      header('Content-Disposition: attachment;filename="'.$fileName.'"');
      header('Cache-Control: max-age=0');
  
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
      $objWriter-&gt;save('php://output');
      die();
  }
  
  /**
  * Create excel by from ajax request
  */
  function xlscreation_ajax() {
  
      $reportdetails = report_details();
  
      require_once SITEPATH . 'PHPExcel/Classes/PHPExcel.php';
  
      $objPHPExcel = new PHPExcel(); 
      $objPHPExcel-&gt;getProperties()
              -&gt;setCreator("user")
              -&gt;setLastModifiedBy("user")
              -&gt;setTitle("Office 2007 XLSX Test Document")
              -&gt;setSubject("Office 2007 XLSX Test Document")
              -&gt;setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
              -&gt;setKeywords("office 2007 openxml php")
              -&gt;setCategory("Test result file");
  
      // Set the active Excel worksheet to sheet 0
      $objPHPExcel-&gt;setActiveSheetIndex(0); 
  
      // Initialise the Excel row number
      $rowCount = 0; 
  
      // Sheet cells
      $cell_definition = array(
          'A' =&gt; 'BrandIcon',
          'B' =&gt; 'Comapany',
          'C' =&gt; 'Rank',
          'D' =&gt; 'Link'
      );
  
      // Build headers
      foreach( $cell_definition as $column =&gt; $value )
      {
          $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension("{$column}")-&gt;setAutoSize(true);
          $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue( "{$column}1", $value ); 
      }
  
      // Build cells
      while( $rowCount &lt; count($reportdetails) ){ 
          $cell = $rowCount + 2;
          foreach( $cell_definition as $column =&gt; $value ) {
  
              $objPHPExcel-&gt;getActiveSheet()-&gt;getRowDimension($rowCount + 2)-&gt;setRowHeight(35); 
  
              switch ($value) {
                  case 'BrandIcon':
                      if (file_exists($reportdetails[$rowCount][$value])) {
                          $objDrawing = new PHPExcel_Worksheet_Drawing();
                          $objDrawing-&gt;setName('Customer Signature');
                          $objDrawing-&gt;setDescription('Customer Signature');
                          //Path to signature .jpg file
                          $signature = $reportdetails[$rowCount][$value];    
                          $objDrawing-&gt;setPath($signature);
                          $objDrawing-&gt;setOffsetX(25);                     //setOffsetX works properly
                          $objDrawing-&gt;setOffsetY(10);                     //setOffsetY works properly
                          $objDrawing-&gt;setCoordinates($column.$cell);             //set image to cell 
                          $objDrawing-&gt;setWidth(32);  
                          $objDrawing-&gt;setHeight(32);                     //signature height  
                          $objDrawing-&gt;setWorksheet($objPHPExcel-&gt;getActiveSheet());  //save 
                      } else {
                          $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($column.$cell, "Image not found" ); 
                      }
                      break;
                  case 'Link':
                      //set the value of the cell
                      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue($column.$cell, $reportdetails[$rowCount][$value]);
                      //change the data type of the cell
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($column.$cell)-&gt;setDataType(PHPExcel_Cell_DataType::TYPE_STRING2);
                      ///now set the link
                      $objPHPExcel-&gt;getActiveSheet()-&gt;getCell($column.$cell)-&gt;getHyperlink()-&gt;setUrl(strip_tags($reportdetails[$rowCount][$value]));
                      break;
  
                  default:
                      $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($column.$cell, $reportdetails[$rowCount][$value] ); 
                      break;
              }
  
          }
  
          $rowCount++; 
      } 
  
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
      $saveExcelToLocalFile = saveExcelToLocalFile($objWriter);
      $response = array(
           'success' =&gt; true,
           'filename' =&gt; $saveExcelToLocalFile['filename'],
           'url' =&gt; $saveExcelToLocalFile['filePath']
      );
      echo json_encode($response);
      die();
  }
  
  function saveExcelToLocalFile($objWriter) {
  
      $rand = rand(1234, 9898);
      $presentDate = date('YmdHis');
      $fileName = "report_" . $rand . "_" . $presentDate . ".xlsx";
  
      // make sure you have permission to write to directory
      $filePath = SITEPATH . 'reports/' . $fileName;
      $objWriter-&gt;save($filePath);
      $data = array(
          'filename' =&gt; $fileName,
          'filePath' =&gt; $filePath
      );
      return $data;
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>Please help me.</p>