当前位置: 首页>>代码示例>>PHP>>正文


PHP mime_content_type函数代码示例

本文整理汇总了PHP中mime_content_type函数的典型用法代码示例。如果您正苦于以下问题:PHP mime_content_type函数的具体用法?PHP mime_content_type怎么用?PHP mime_content_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mime_content_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * @param mixed:string|\SplFileInfo $input
  * @param array $options
  * @throws ParseException
  * @return array
  */
 public static function parse($input, array $options = array())
 {
     $default_options = array('delimiter' => ';', 'encoding_source' => 'UTF-8', 'encoding_target' => 'UTF-8');
     $options = array_merge($default_options, $options);
     // if input is a file, process it
     $file = null;
     if (false === strpos($input, '\\r\\n') && is_file($input)) {
         if (false === is_readable($input)) {
             throw new ParseException(sprintf('Unable to parse \'%s\' as the file is not readable.', $input));
         }
         if ($input instanceof \SplFileInfo) {
             if (!in_array(mime_content_type($input->getPathname()), array('text/csv', 'text/plain'))) {
                 throw new ParseException('This is not a CSV file.');
             }
         } else {
             if (!in_array(mime_content_type($input), array('text/csv', 'text/plain'))) {
                 throw new ParseException('This is not a CSV file.');
             }
         }
         $file = $input;
         $input = file_get_contents($file);
     }
     $csv = new Csv\Parser();
     try {
         return $csv->parse($input, $options['delimiter'], $options);
     } catch (ParseException $e) {
         if (!is_null($file)) {
             $e->setParsedFile($file);
         }
         throw $e;
     }
 }
开发者ID:zebba,项目名称:loader,代码行数:38,代码来源:Csv.php

示例2: play

 /**
  * Play/stream a song.
  *
  * @link https://github.com/phanan/koel/wiki#streaming-music
  *
  * @param Song      $song      The song to stream.
  * @param null|bool $transcode Whether to force transcoding the song.
  *                             If this is omitted, by default Koel will transcode FLAC.
  * @param null|int  $bitRate   The target bit rate to transcode, defaults to OUTPUT_BIT_RATE.
  *                             Only taken into account if $transcode is truthy.
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function play(Song $song, $transcode = null, $bitRate = null)
 {
     if ($song->s3_params) {
         return (new S3Streamer($song))->stream();
     }
     // If `transcode` parameter isn't passed, the default is to only transcode FLAC.
     if ($transcode === null && ends_with(mime_content_type($song->path), 'flac')) {
         $transcode = true;
     }
     $streamer = null;
     if ($transcode) {
         $streamer = new TranscodingStreamer($song, $bitRate ?: config('koel.streaming.bitrate'), request()->input('time', 0));
     } else {
         switch (config('koel.streaming.method')) {
             case 'x-sendfile':
                 $streamer = new XSendFileStreamer($song);
                 break;
             case 'x-accel-redirect':
                 $streamer = new XAccelRedirectStreamer($song);
                 break;
             default:
                 $streamer = new PHPStreamer($song);
                 break;
         }
     }
     $streamer->stream();
 }
开发者ID:phanan,项目名称:koel,代码行数:40,代码来源:SongController.php

示例3: processemail

 public static function processemail($emailsrc, $pdfout, $coverfile = '')
 {
     $combfilelist = array();
     # Process the email
     $emailparts = Mail_mimeDecode::decode(array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => true, 'input' => file_get_contents($emailsrc), 'crlf' => "\r\n"));
     # Process the cover if it exists
     if ($coverfile !== '') {
         $combfilelist[] = self::processpart(file_get_contents($coverfile), mime_content_type($coverfile));
     }
     # Process the parts
     $combfilelist = array_merge($combfilelist, self::processparts($emailparts));
     # Create an intermediate file to build the pdf
     $tmppdffilename = sys_get_temp_dir() . '/e2p-' . (string) abs((int) (microtime(true) * 100000)) . '.pdf';
     # Build the command to combine all of the intermediate files into one
     $conbcom = str_replace(array_merge(array('INTFILE', 'COMBLIST'), array_keys(self::$driver_paths)), array_merge(array($tmppdffilename, implode(' ', $combfilelist)), array_values(self::$driver_paths)), self::$mime_drivers['gs']);
     exec($conbcom);
     # Remove the intermediate files
     foreach ($combfilelist as $combfilename) {
         unlink($combfilename);
     }
     # Write the intermediate file to the final destination
     $intfileres = fopen($tmppdffilename, 'rb');
     $outfileres = fopen($pdfout, 'ab');
     while (!feof($intfileres)) {
         fwrite($outfileres, fread($intfileres, 8192));
     }
     fclose($intfileres);
     fclose($outfileres);
     # Remove the intermediate file
     unlink($tmppdffilename);
 }
开发者ID:swk,项目名称:bluebox,代码行数:31,代码来源:emailtopdf.php

示例4: imageManager

 public function imageManager()
 {
     $response = array();
     // Image types.
     $image_types = array("image/gif", "image/jpeg", "image/pjpeg", "image/jpeg", "image/pjpeg", "image/png", "image/x-png");
     // Filenames in the uploads folder.
     $fnames = scandir(BASE . "/files/site/uploads/");
     // Check if folder exists.
     if ($fnames) {
         // Go through all the filenames in the folder.
         foreach ($fnames as $name) {
             // Filename must not be a folder.
             if (!is_dir($name)) {
                 // Check if file is an image.
                 if (in_array(mime_content_type(getcwd() . "/files/site/uploads/" . $name), $image_types)) {
                     // Build the image.
                     $img = new StdClass();
                     $img->url = "/files/site/uploads/" . $name;
                     $img->thumb = "/files/site/uploads/" . $name;
                     $img->name = $name;
                     // Add to the array of image.
                     array_push($response, $img);
                 }
             }
         }
     } else {
         $response = new StdClass();
         $response->error = "Images folder does not exist!";
     }
     $response = json_encode($response);
     // Send response.
     echo stripslashes($response);
 }
开发者ID:sereg,项目名称:mebel,代码行数:33,代码来源:Floara.php

示例5: check

 /**
  * Check file mime type
  * @access	public
  * @param 	string $name
  * @param 	string $path
  * @param 	string $type
  * @return 	bool
  */
 public function check($name, $path)
 {
     $extension = strtolower(substr($name, strrpos($name, '.') + 1));
     $mimetype = null;
     if (function_exists('finfo_open')) {
         if (!($finfo = new finfo(FILEINFO_MIME_TYPE))) {
             return true;
         }
         $mimetype = $finfo->file($path);
     } else {
         if (function_exists('mime_content_type')) {
             $mimetype = @mime_content_type($path);
         }
     }
     if ($mimetype) {
         $mime = self::getMime($mimetype);
         if ($mime) {
             if (!in_array($extension, $mime)) {
                 return false;
             }
         }
     }
     // server doesn't support mime type check, let it through...
     return true;
 }
开发者ID:spikart,项目名称:spikart.com.ua,代码行数:33,代码来源:mime.php

示例6: next

 /**
  * Processes the next item on the work queue. Emits a JSON messages to
  * indicate current progress.
  *
  * Returns:
  * TRUE/NULL if the migration was successful
  */
 function next()
 {
     # Fetch next item -- use the last item so the array indices don't
     # need to be recalculated for every shift() operation.
     $info = array_pop($this->queue);
     # Attach file to the ticket
     if (!($info['data'] = @file_get_contents($info['path']))) {
         # Continue with next file
         return $this->error(sprintf('%s: Cannot read file contents', $info['path']));
     }
     # Get the mime/type of each file
     # XXX: Use finfo_buffer for PHP 5.3+
     $info['type'] = mime_content_type($info['path']);
     if (!($fileId = AttachmentFile::save($info))) {
         return $this->error(sprintf('%s: Unable to migrate attachment', $info['path']));
     }
     # Update the ATTACHMENT_TABLE record to set file_id
     db_query('update ' . TICKET_ATTACHMENT_TABLE . ' set file_id=' . db_input($fileId) . ' where attach_id=' . db_input($info['attachId']));
     # Remove disk image of the file. If this fails, the migration for
     # this file would not be retried, because the file_id in the
     # TICKET_ATTACHMENT_TABLE has a nonzero value now
     if (!@unlink($info['path'])) {
         $this->error(sprintf('%s: Unable to remove file from disk', $info['path']));
     }
     # TODO: Log an internal note to the ticket?
     return true;
 }
开发者ID:nicolap,项目名称:osTicket-1.7,代码行数:34,代码来源:class.attachment.migrate.php

示例7: resize

 public function resize($filename, $dst, $dst_w, $dst_h)
 {
     list($width, $height) = getimagesize($filename);
     $center_width = $width > $height ? $dst_w * $height / $dst_h : $width;
     $center_height = $height > $width ? $dst_h * $width / $dst_w : $height;
     $src_x = $width > $height ? ($width - $center_width) / 2 : 0;
     $src_y = $height > $width ? ($height - $center_height) / 2 : 0;
     $thumb = imagecreatetruecolor($dst_w, $dst_h);
     $type = mime_content_type($filename);
     switch (substr($type, 6)) {
         case 'jpeg':
             $source = imagecreatefromjpeg($filename);
             imagecopyresampled($thumb, $source, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $center_width, $center_height);
             imagejpeg($thumb, $dst);
             break;
         case 'gif':
             $source = imagecreatefromgif($filename);
             imagecopyresampled($thumb, $source, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $center_width, $center_height);
             imagegif($thumb, $dst);
             break;
         case 'png':
             $source = imagecreatefrompng($filename);
             imagecopyresampled($thumb, $source, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $center_width, $center_height);
             imagepng($thumb, $dst);
             break;
     }
     imagedestroy($thumb);
 }
开发者ID:jg42,项目名称:compicture,代码行数:28,代码来源:ImgResizer.php

示例8: check

 function check($contents, $file)
 {
     $this->scanned_files[] = $file;
     if (preg_match('/<\\?php/', $contents) == false) {
         return;
     }
     $infected = false;
     foreach ($this->scan_patterns as $pattern) {
         if (preg_match($pattern, $contents)) {
             if ($file !== __FILE__) {
                 $this->infected_files[] = array('file' => $file, 'pattern_matched' => $pattern);
                 $infected = true;
                 break;
             }
         }
     }
     if (substr($file, -4) == '.php') {
         $mime = mime_content_type($file);
         $mime_a = explode('/', $mime);
         if ($mime_a[0] != "text") {
             if ($infected) {
                 $pattern_desc = $this->infected_files[count($this->infected_files) - 1]['pattern_matched'];
                 $this->infected_files[count($this->infected_files) - 1]['pattern_matched'] = $pattern_desc . " - suspicious mime ({$mime})";
             } else {
                 $this->infected_files[count($this->infected_files) - 1]['pattern_matched'] = array('file' => $file, 'pattern_matched' => "suspicious mime type ({$mime})");
             }
         }
     }
 }
开发者ID:redPanther,项目名称:Malicious-Code-Scanner,代码行数:29,代码来源:phpMalCodeScanner.php

示例9: getMimeType

 /**
  * Detects the MIME type of a given file
  * @param string $fileName The full path to the name whose MIME type you want to find out
  * @return string The MIME type, e.g. image/jpeg
  */
 static function getMimeType($fileName)
 {
     $mime = null;
     // Try fileinfo first
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME);
         if ($finfo !== false) {
             $mime = finfo_file($finfo, $fileName);
             finfo_close($finfo);
         }
     }
     // Fallback to mime_content_type() if finfo didn't work
     if (is_null($mime) && function_exists('mime_content_type')) {
         $mime = mime_content_type($fileName);
     }
     // Final fallback, detection based on extension
     if (is_null($mime)) {
         $extension = self::getTypeIcon(getTypeIcon);
         if (array_key_exists($extension, self::$mimeMap)) {
             $mime = self::$mimeMap[$extension];
         } else {
             $mime = "application/octet-stream";
         }
     }
     return $mime;
 }
开发者ID:jlleblanc,项目名称:joomla-media-manager,代码行数:31,代码来源:media.php

示例10: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     /* @var $request Request */
     $request = $event->getRequest();
     $file = $request->getScriptName() == '/app_dev.php' ? $request->getPathInfo() : $request->getScriptName();
     if (is_file($file = $this->root_dir . '/../web' . $file)) {
         $response = (new Response())->setPublic();
         // caching in prod env
         if ($this->env == 'prod') {
             $response->setEtag(md5_file($file))->setExpires((new \DateTime())->setTimestamp(time() + 2592000))->setLastModified((new \DateTime())->setTimestamp(filemtime($file)))->headers->addCacheControlDirective('must-revalidate', true);
             // response was not modified for this request
             if ($response->isNotModified($request)) {
                 $event->setResponse($response);
                 return;
             }
         }
         // set content type
         $mimes = ['css' => 'text/css', 'js' => 'text/javascript'];
         if (isset($mimes[$ext = pathinfo($file, PATHINFO_EXTENSION)])) {
             $response->headers->set('Content-Type', $mimes[$ext]);
         } else {
             $response->headers->set('Content-Type', mime_content_type($file));
         }
         $event->setResponse($response->setContent(file_get_contents($file)));
     }
 }
开发者ID:anime-db,项目名称:anime-db,代码行数:32,代码来源:StaticFiles.php

示例11: download

 public function download($nombre)
 {
     $path = PATH_FILES . $nombre;
     $type = '';
     if (is_file($path)) {
         $size = filesize($path);
         if (function_exists('mime_content_type')) {
             $type = mime_content_type($path);
         } else {
             if (function_exists('finfo_file')) {
                 $info = finfo_open(FILEINFO_MIME);
                 $type = finfo_file($info, $path);
                 finfo_close($info);
             }
         }
         if ($type == '') {
             $type = "application/force-download";
         }
         header("Content-Type: {$type}");
         header("Content-Disposition: attachment; filename={$nombre}");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . $size);
         readfile($path);
     } else {
         die("El archivo no existe.");
     }
 }
开发者ID:efaby,项目名称:postulacion,代码行数:27,代码来源:File.php

示例12: getMime

	public static function getMime($file)
	{
		// Check if file is an image.
		$info = @getimagesize($file);

		if ($info)
		{
			$type = $info['mime'];
		}
		elseif (function_exists('finfo_open'))
		{
			// We have fileinfo.
			$finfo = finfo_open(FILEINFO_MIME_TYPE);
			$type  = finfo_file($finfo, $file);
			finfo_close($finfo);
		}
		elseif (function_exists('mime_content_type'))
		{
			// We have mime magic.
			$type = mime_content_type($file);
		}
		else
		{
			$type = false;
		}

		return $type;
	}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:28,代码来源:file.php

示例13: getArchiveFormat

 /**
  * Detect archive format
  *
  * @param string $filePath archive file path
  *
  * @return string archive format see $_availableFormats property values
  */
 public static function getArchiveFormat($filePath)
 {
     if (!is_readable($filePath)) {
         throw new BaseZF_Archive_Exception(sprintf('Could not open file "%s"', $filePath));
     }
     $extention = pathinfo($filePath, PATHINFO_EXTENSION);
     $mimeType = null;
     // use $minType only if mime_content_type is available
     if (function_exists('mime_content_type')) {
         $mimeType = trim(mime_content_type($filePath));
     }
     // compare mine types
     foreach (self::$_availableFormats as $formatExtention => $format) {
         $className = self::_getClassNameByFormat($format);
         $formatMimeType = call_user_func($className . '::getFileMimeType');
         if (!is_null($mimeType) && $formatMimeType == $mimeType) {
             return $format;
         } else {
             if ($extention == $formatExtention) {
                 return $format;
             }
         }
     }
     // no mine types match
     if (!is_null($mimeType)) {
         throw new BaseZF_Archive_Exception(sprintf('Could not detect archive format for file "%s", with mine type "%s"', $filePath, $mimeType));
     } else {
         throw new BaseZF_Archive_Exception(sprintf('Could not detect archive format for file "%s"', $filePath));
     }
 }
开发者ID:rlecellier,项目名称:basezf,代码行数:37,代码来源:Archive.php

示例14: autocompleteTrack

 /**
  * Completes track information from a given path using mediainfo.
  * @param Track $track
  */
 public function autocompleteTrack(Track $track)
 {
     $only_audio = true;
     //initialized true until video track is found.
     if (!$track->getPath()) {
         throw new \BadMethodCallException('Input track has no path defined');
     }
     $json = json_decode($this->getMediaInfo($track->getPath()));
     if (!$this->jsonHasMediaContent($json)) {
         throw new \InvalidArgumentException("This file has no accesible video " . "nor audio tracks\n" . $track->getPath());
     }
     $track->setMimetype(mime_content_type($track->getPath()));
     $track->setBitrate(intval($json->format->bit_rate));
     $aux = intval((string) $json->format->duration);
     $track->setDuration(ceil($aux));
     $track->setSize((string) $json->format->size);
     foreach ($json->streams as $stream) {
         switch ((string) $stream->codec_type) {
             case "video":
                 $track->setVcodec((string) $stream->codec_name);
                 $track->setFramerate((string) $stream->avg_frame_rate);
                 $track->setWidth(intval($stream->width));
                 $track->setHeight(intval($stream->height));
                 $only_audio = false;
                 break;
             case "audio":
                 $track->setAcodec((string) $stream->codec_name);
                 $track->setChannels(intval($stream->channels));
                 break;
         }
         $track->setOnlyAudio($only_audio);
     }
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:37,代码来源:InspectionFfprobeService.php

示例15: upload

 public function upload($file)
 {
     $filePath = realpath($this->filenames['basePath'] . $file);
     $binary = file_get_contents($filePath);
     $binaryLength = strlen($binary);
     $chunkLength = 1024 * 1024;
     $chunks = str_split($binary, $chunkLength);
     $mimeType = mime_content_type($filePath);
     foreach ($chunks as $chunkIndex => $chunk) {
         $chunkSize = strlen($chunk);
         $tempFileName = tempnam('/tmp/', 'file-');
         file_put_contents($tempFileName, $chunk);
         $fileUpload = new UploadedFile($tempFileName, $file, $mimeType);
         $data = array('flowChunkNumber' => $chunkIndex + 1, 'flowChunkSize' => $chunkLength, 'flowCurrentChunkSize' => $chunkSize, 'flowTotalSize' => $binaryLength, 'flowIdentifier' => $binaryLength . $file, 'flowFilename' => $file, 'flowRelativePath' => $file, 'flowTotalChunks' => count($chunks));
         $this->client->request('GET', '/' . $this->api['backend'] . '/media/upload/image/', $data, [], ['CONTENT_TYPE' => 'application/json']);
         $this->client->request('POST', '/' . $this->api['backend'] . '/media/upload/image/', $data, ['file' => $fileUpload], ['CONTENT_TYPE' => 'application/json']);
     }
     $response = $this->client->getResponse();
     $content = $response->getContent();
     $statusCode = $response->getStatusCode();
     $result = json_decode($content, true);
     $this->assertEquals($statusCode, 201);
     $this->assertNotNull($result);
     $image = $this->dm->getRepository('Aisel\\MediaBundle\\Document\\Media')->findOneBy(['id' => $result['id']]);
     $filePath = realpath($this->filenames['basePath'] . $file);
     $binary = file_get_contents($filePath);
     $binaryLength = strlen($binary);
     $uploadedFile = realpath(static::$kernel->getContainer()->getParameter('assetic.write_to') . $image->getFilename());
     $uploadedBinary = file_get_contents($uploadedFile);
     $uploadedBinaryLength = strlen($uploadedBinary);
     $this->assertEquals($image->getType(), 'image');
     $this->assertEquals($uploadedBinaryLength, $binaryLength);
     return $result;
 }
开发者ID:Brother-Simon,项目名称:Aisel,代码行数:34,代码来源:UploadControllerTest.php


注:本文中的mime_content_type函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。