Exemple #1
0
 /**
  * @param  MediaFile  $mediaFile
  * @param  string     $host
  * @param  string     $post
  * @param  string     $head
  * @param  string     $tail
  * @return bool|array
  */
 protected function sendData(MediaFile $mediaFile, $host, $post, $head, $tail)
 {
     $sock = fsockopen("ssl://" . $host, 443);
     fwrite($sock, $post);
     fwrite($sock, $head);
     //write file data
     $buf = 1024;
     $totalread = 0;
     $fp = fopen($mediaFile->getFilepath(), "r");
     while ($totalread < $mediaFile->getSize()) {
         $buff = fread($fp, $buf);
         fwrite($sock, $buff, $buf);
         $totalread += $buf;
     }
     //echo $TAIL;
     fwrite($sock, $tail);
     sleep(1);
     $data = fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     $data .= fgets($sock, 8192);
     fclose($sock);
     list($header, $body) = preg_split("/\\R\\R/", $data, 2);
     $json = json_decode($body, true);
     if (is_array($json)) {
         return $json;
     }
     return false;
 }
 /**
  * @param  MediaFile   $mediaFile
  * @return null|string
  */
 protected function checkMediaFileType(MediaFile $mediaFile)
 {
     $mimeType = $mediaFile->getMimeType();
     if (0 === strpos($mimeType, 'image')) {
         return MediaFileInterface::TYPE_IMAGE;
     } elseif (0 === strpos($mimeType, 'video')) {
         return MediaFileInterface::TYPE_VIDEO;
     } elseif (0 === strpos($mimeType, 'audio')) {
         return MediaFileInterface::TYPE_VIDEO;
     }
     $map = $this->getExtensionTypeMap();
     if (isset($map[$mediaFile->getExtension()])) {
         return $map[$mediaFile->getExtension()];
     }
     return null;
 }