title: MP4 videos served from a PHP script on IIS (Azure) only plays audio with Safari
body: <p>I'm trying to serve a mp4 video from a PHP script. In all browsers works without problem, but when I try with Safari the video plays only with sound (without image).</p>
  
  <p>The problem happens only with Safari and IIS, I tried with Safari and Apache and works fine.</p>
  
  <p>If I try view the video directly from the server (without the PHP script) it works perfectly.</p>
  
  <p>The code of the PHP script:</p>
  
  <pre><code>public function video() {
      $params = Manager::getParams();
  
      if (array_key_exists(2, $params)) {
          $filename = $params[2];
  
          $path = VIDEOS_FOLDER . $filename;
          $mime = 'video/mp4';
  
          $this-&gt;get_file($path, $mime);
      } else {
          echo "Incorrect params";
      }
  }
  
  private function get_file($path, $mime) {
      // Clears the cache and prevent unwanted output
      ob_clean();
      session_write_close();
      @ini_set('error_reporting', E_ALL &amp; ~ E_NOTICE);
      //@apache_setenv('no-gzip', 1);
      @ini_set('zlib.output_compression', 'Off');
  
      $size = filesize($path); // The size of the file
      // Send the content type header
      header('Content-type: ' . $mime);
  
      // Check if it's a HTTP range request
      if (isset($_SERVER['HTTP_RANGE'])) {
          // Parse the range header to get the byte offset
          $ranges = array_map(
                  'intval', // Parse the parts into integer
                  explode('-', // The range separator
                          substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header
                  )
          );
  
          // If the last range param is empty, it means the EOF (End of File)
          if (!$ranges[1]) {
              $ranges[1] = $size - 1;
          }
  
          // Send the appropriate headers
          header('HTTP/1.1 206 Partial Content');
          header('Accept-Ranges: bytes');
          header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range
          // Send the ranges we offered
          header(
                  sprintf(
                          'Content-Range: bytes %d-%d/%d', // The header format
                          $ranges[0], // The start range
                          $ranges[1], // The end range
                          $size // Total size of the file
                  )
          );
  
          // It's time to output the file
          $f = fopen($path, 'rb'); // Open the file in binary mode
          $chunkSize = 8192; // The size of each chunk to output
          // Seek to the requested start range
          fseek($f, $ranges[0]);
  
          // Start outputting the data
          while (true) {
              // Check if we have outputted all the data requested
              if (ftell($f) &gt;= $ranges[1]) {
                  break;
              }
  
              // Output the data
              echo fread($f, $chunkSize);
  
              // Flush the buffer immediately
              @ob_flush();
              flush();
          }
      } else {
          // It's not a range request, output the file anyway
          header('Content-Length: ' . $size);
  
          // Read the file
          @readfile($path);
  
          // and flush the buffer
          @ob_flush();
          flush();
      }
  }
  </code></pre>
  
  <p>My problem becomes when I play the video on Safari with IIS server, it just play the sound.</p>
  
  <p>I added the following to the web.config:</p>
  
  <pre><code>&lt;staticContent&gt;
      &lt;mimeMap fileExtension=".mp4" mimeType="video/mp4" /&gt;
  &lt;/staticContent&gt;
  </code></pre>
  
  <p>Does anyone know how to fix it? </p>