コード例 #1
1
 function __construct($interface, $files_directory)
 {
     $field = filter_input(INPUT_POST, 'field', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     // Check for file upload.
     if ($field === NULL || empty($_FILES) || !isset($_FILES['file'])) {
         return;
     }
     $this->interface = $interface;
     // Create a new result object.
     $this->result = new stdClass();
     // Set directory.
     $this->files_directory = $files_directory;
     // Create the temporary directory if it doesn't exist.
     $dirs = array('', '/files', '/images', '/videos', '/audios');
     foreach ($dirs as $dir) {
         if (!H5PCore::dirReady($this->files_directory . $dir)) {
             $this->result->error = $this->interface->t('Unable to create directory.');
             return;
         }
     }
     // Get the field.
     $this->field = json_decode($field);
     if (function_exists('finfo_file')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $this->type = finfo_file($finfo, $_FILES['file']['tmp_name']);
         finfo_close($finfo);
     } elseif (function_exists('mime_content_type')) {
         // Deprecated, only when finfo isn't available.
         $this->type = mime_content_type($_FILES['file']['tmp_name']);
     } else {
         $this->type = $_FILES['file']['type'];
     }
     $this->extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
     $this->size = $_FILES['file']['size'];
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: Helper.php プロジェクト: zachborboa/php-curl-class
 function mime_type($file_path)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime_type = finfo_file($finfo, $file_path);
     finfo_close($finfo);
     return $mime_type;
 }
コード例 #4
0
ファイル: RoutesCollection.php プロジェクト: tomaka17/niysu
 /**
  * Registers all the files of a static directory as resources.
  *
  * @param string 	$path 		The absolute path on the server which contains the files
  * @param string 	$prefix 	A prefix to add to the name of the static files
  * @return Route
  */
 public function registerStaticDirectory($path)
 {
     $path = rtrim($path, '/\\');
     return $this->register('/{file}', 'get')->pattern('file', '([^\\.]{2,}.*|.)')->name($path)->before(function (&$file, &$isRightResource) use($path) {
         $file = $path . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file);
         if (!file_exists($file) || is_dir($file)) {
             $isRightResource = false;
             return;
         }
     })->before(function ($file, $etagResponseFilter) {
         $etagResponseFilter->setEtag(md5($file . filemtime($file)));
     })->handler(function ($file, $response, $elapsedTime) {
         if (!extension_loaded('fileinfo')) {
             throw new \LogicException('The "fileinfo" extension must be activated');
         }
         $finfo = finfo_open(FILEINFO_MIME);
         $mime = finfo_file($finfo, $file);
         finfo_close($finfo);
         $pathinfo = pathinfo($file);
         if ($pathinfo['extension'] == 'css') {
             $mime = 'text/css';
         }
         if ($pathinfo['extension'] == 'js') {
             $mime = 'application/javascript';
         }
         if ($pathinfo['extension'] == 'svg') {
             $mime = 'image/svg+xml';
         }
         if (substr($mime, 0, 15) == 'application/xml' && ($pathinfo['extension'] == 'htm' || $pathinfo['extension'] == 'html')) {
             $mime = 'application/xhtml+xml';
         }
         $response->setHeader('Content-Type', $mime);
         $response->appendData(file_get_contents($file));
     });
 }
コード例 #5
0
ファイル: File.php プロジェクト: vojtabiberle/MediaStorage
 /**
  * @return string
  */
 public function getContentType()
 {
     if (is_null($this->content_type)) {
         $this->content_type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->getFullPath());
     }
     return $this->content_type;
 }
コード例 #6
0
ファイル: CloudFlareController.php プロジェクト: arbi/MyCode
 public function downloadAction()
 {
     try {
         $fileName = 'problematic_file.pdf';
         $filePath = '/ginosi/uploads/product/documents/553/2015_1421387867_Hollywood_Boulevard_Studio_Insurance_Contract_719.pdf';
         $fhandle = finfo_open(FILEINFO_MIME);
         $mime_type = finfo_file($fhandle, $filePath);
         header('Content-Type: ' . $mime_type);
         //header("Content-Length: " . filesize($filePath));
         header('Content-Disposition: attachment; filename="' . $fileName . '"');
         header('Content-Transfer-Encoding: binary');
         header('Cache-Control: no-cache');
         header('Accept-Ranges: bytes');
         // expence file download way
         //            if (file_exists($filePath)) {
         //                readfile($filePath);
         //                return true;
         //            }
         // apartment docs file download way
         echo file_get_contents($filePath, true);
         return;
     } catch (\Exception $ex) {
         echo $ex->getMessage();
     }
 }
コード例 #7
0
 /**
  * @return resource
  */
 public static function fInstance()
 {
     if (null === self::$fInstance) {
         return finfo_open(FILEINFO_MIME);
     }
     return self::$fInstance;
 }
コード例 #8
0
ファイル: mime.php プロジェクト: DanyCan/wisten.github.io
 /**
  * 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));
     if (function_exists('finfo_open')) {
         if ($finfo = @finfo_open(FILEINFO_MIME_TYPE)) {
             if ($mimetype = @finfo_file($finfo, $path)) {
                 @finfo_close($finfo);
                 $mime = self::getMime($mimetype);
                 if ($mime) {
                     return in_array($extension, $mime);
                 }
             }
         }
     } else {
         if (function_exists('mime_content_type')) {
             if ($mimetype = @mime_content_type($path)) {
                 $mime = self::getMime($mimetype);
                 if ($mime) {
                     return in_array($extension, $mime);
                 }
             }
         }
     }
     // server doesn't support mime type check, let it through...
     return true;
 }
コード例 #9
0
 private function fileMimeType($filePath)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $type = finfo_file($finfo, $filePath);
     finfo_close($finfo);
     return $type;
 }
コード例 #10
0
ファイル: filemimetype.php プロジェクト: RazorMarx/izend
/**
 *
 * @copyright  2010-2015 izend.org
 * @version    7
 * @link       http://www.izend.org
 */
function file_mime_type($file, $encoding = true)
{
    $mime = false;
    if (function_exists('finfo_file')) {
        $finfo = finfo_open(FILEINFO_MIME);
        $mime = @finfo_file($finfo, $file);
        finfo_close($finfo);
    } else {
        if (substr(PHP_OS, 0, 3) == 'WIN') {
            $mime = mime_content_type($file);
        } else {
            $file = escapeshellarg($file);
            $cmd = "file -iL {$file}";
            exec($cmd, $output, $r);
            if ($r == 0) {
                $mime = substr($output[0], strpos($output[0], ': ') + 2);
            }
        }
    }
    if (!$mime) {
        return false;
    }
    if ($encoding) {
        return $mime;
    }
    return substr($mime, 0, strpos($mime, '; '));
}
コード例 #11
0
ファイル: File.php プロジェクト: moiseh/codegen
 public function getType()
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $type = finfo_file($finfo, $this->getFullPath());
     finfo_close($finfo);
     return $type;
 }
コード例 #12
0
ファイル: media-upload.ajax.php プロジェクト: koyach/dalite
function getUploadedFile($name)
{
    $tmp_name = $_FILES[$name]['tmp_name'];
    $info = finfo_open(FILEINFO_MIME_TYPE);
    $mime_type = finfo_file($info, $tmp_name);
    finfo_close($info);
    $extension = '';
    switch ($mime_type) {
        case 'image/jpeg':
            $extension = 'jpg';
            break;
        case 'image/gif':
            $extension = 'gif';
            break;
        case 'image/png':
            $extension = 'png';
            break;
        default:
            $extension = '';
    }
    if ($extension != '') {
        $image_name = pathinfo($_FILES[$name]['name'])['filename'] . '.' . $extension;
        $image_file = 'img-uploads/' . $image_name;
        try {
            move_uploaded_file($tmp_name, $image_file);
        } catch (Exception $e) {
            print_r($e);
        }
    }
    return $image_name;
}
コード例 #13
0
ファイル: fs.php プロジェクト: Rudi9719/lucid
 function mime_content_type($filename)
 {
     $finfo = finfo_open(FILEINFO_MIME);
     $mimetype = finfo_file($finfo, $filename);
     finfo_close($finfo);
     return $mimetype;
 }
コード例 #14
0
ファイル: ImageGD.php プロジェクト: nicolargo/frontend
 /**
  * Loads an image from a file path
  *
  * @param string $filename Full path to the file which will be manipulated
  * @return ImageGD
  */
 public function load($filename)
 {
     if (function_exists("finfo_open")) {
         // not supported everywhere https://github.com/openphoto/frontend/issues/368
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $this->type = finfo_file($finfo, $filename);
     } else {
         if (function_exists("mime_content_type")) {
             $this->type = mime_content_type($filename);
         } else {
             if (function_exists('exec')) {
                 $this->type = exec('/usr/bin/file --mime-type -b ' . escapeshellarg($filename));
                 if (!empty($this->type)) {
                     $this->type = "";
                 }
             }
         }
     }
     if (preg_match('/png$/', $this->type)) {
         $this->image = imagecreatefrompng($filename);
     } elseif (preg_match('/gif$/', $this->type)) {
         $this->image = @imagecreatefromgif($filename);
     } else {
         $this->image = @imagecreatefromjpeg($filename);
     }
     if (!$this->image) {
         OPException::raise(new OPInvalidImageException('Could not create image with GD library'));
     }
     $this->width = imagesx($this->image);
     $this->height = imagesy($this->image);
     return $this;
 }
コード例 #15
0
 /**
  * @param string $file
  * @return FileAnalysisResult
  */
 public static function analyse($file)
 {
     //check if file exists
     if (false === file_exists($file)) {
         return null;
     }
     //is not a file
     if (false === is_file($file)) {
         return null;
     }
     //get file size
     $size = filesize($file);
     $mimeType = null;
     //mime type getter
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $mimeType = finfo_file($finfo, $file);
     } else {
         if (function_exists('mime_content_type')) {
             $mimeType = mime_content_type($file);
         }
     }
     //default mime type
     if (strlen($mimeType) == 0) {
         //default mime type
         $mimeType = 'application/octet-stream';
     }
     return new FileAnalysisResult($mimeType, $size, $file);
 }
コード例 #16
0
function forceDownload($file)
{
    //Check file exist or not
    if (file_exists($file)) {
        if (ini_get('zlib.output_compression')) {
            // required for IE
            ini_set('zlib.output_compression', 'Off');
        }
        // Get mine type of file.
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        // return mime type ala mimetype extension
        $mimeType = finfo_file($finfo, $file) . "\n";
        finfo_close($finfo);
        header('Expires: 0');
        header('Pragma: public');
        header('Cache-Control: private', false);
        header('Content-Type:' . $mimeType);
        header('Content-Disposition: attachment; filename="' . basename($file) . '"');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Length: ' . filesize($file));
        header('Connection: close');
        readfile($file);
        exit;
    } else {
        return "File does not exist";
    }
}
コード例 #17
0
 public static function fileDownload($filepath, $test = false)
 {
     //prevent transverse above BROWSE_URL dir
     if (strpos(realpath($filepath), realpath(BROWSE_URL)) !== 0) {
         return false;
     }
     //for unit test, no need to download read file
     if ($test) {
         return true;
     }
     if (is_file($filepath)) {
         $size = filesize($filepath);
         if (function_exists('finfo_open')) {
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $mimetype = finfo_file($finfo, $filepath);
             finfo_close($finfo);
         } else {
             $mimetype = 'application/octet-stream';
         }
         //clear all output buffer
         ob_end_clean();
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Cache-Control: private', false);
         header("Content-Type: {$mimetype}");
         header("Content-Disposition: attachment; filename=\"" . basename($filepath) . '"');
         header("Content-length: " . $size);
         header("Content-Transfer-Encoding: binary");
         readfile($filepath);
     } else {
         return false;
     }
 }
コード例 #18
0
ファイル: file-manager.php プロジェクト: borisper1/vesi-cms
function displayFiles($path)
{
    echo "<table class='table table-hover file-list'>\n        <thead><th>Nome</th><th>Dimensione</th><th>Ultima modifica</th></thead>";
    $file_array = array_diff(scandir("../" . $path), array('..', '.', '.DS_Store'));
    foreach ($file_array as $file) {
        $url = "../" . $path . "/" . $file;
        if (is_dir($url)) {
            $name = $file;
            $folder_path = $path . "/" . $file;
            $size = formatBytes(getFolderSize($url), 1);
            $date = date("d/m/Y", stat($url)['mtime']);
            echo "<tr><td><span class='fa-stack fa-2x'><i class='fa fa-folder'></i></span> <a href='#' data-path=\"{$folder_path}\" class='file-list-folder'>{$name}</a>";
            echo "<button type='button' class='btn btn-link pull-right lmb remove-folder tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$folder_path}\"><i class='fa fa-remove'></i></button>";
            echo "<button type='button' class='btn btn-link pull-right lmb edit-folder tooltipped' data-toggle='tooltip' title='Rinomina' data-path=\"{$folder_path}\"><i class='fa fa-edit'></i></button>";
            echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>";
        } else {
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            $content_type = finfo_file($finfo, $url);
            $file_icon = getFileTypeIcon($content_type, $file);
            $size = formatBytes(filesize($url), 1);
            $date = date("d/m/Y", filemtime($url));
            $preview = canPreview($content_type);
            if ($preview == "no") {
                echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href=\"{$url}\" class='file-list' target='_blank'>{$file}</a>";
            } else {
                echo "<tr><td><span class='fa-stack fa-2x'><i class='fa {$file_icon}'></i></span> <a href='#' data-path=\"{$url}\" data-preview_mode='{$preview}' class='file-list-previewable'>{$file}</a>";
            }
            echo "<button type='button' class='btn btn-link pull-right lmb remove-file tooltipped' data-toggle='tooltip' title='Elimina' data-path=\"{$url}\"><i class='fa fa-remove'></i></button>";
            echo "</td><td><span class='text-muted'>{$size}</span></td><td><span class='text-muted'>{$date}</span></td></tr>";
        }
    }
    echo "</table>";
}
コード例 #19
0
ファイル: S3Controller.php プロジェクト: edwardshe/sublite-1
 function getMIME($fname)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $fname);
     finfo_close($finfo);
     return $mime;
 }
コード例 #20
0
ファイル: mime_type_lib.php プロジェクト: rad4n/erekutoro
 function get_file_mime_type($filename, $debug = false)
 {
     if (function_exists('finfo_open') && function_exists('finfo_file') && function_exists('finfo_close')) {
         $fileinfo = finfo_open(FILEINFO_MIME);
         $mime_type = finfo_file($fileinfo, $filename);
         finfo_close($fileinfo);
         if (!empty($mime_type)) {
             if (true === $debug) {
                 return array('mime_type' => $mime_type, 'method' => 'fileinfo');
             }
             return $mime_type;
         }
     }
     if (function_exists('mime_content_type')) {
         $mime_type = mime_content_type($filename);
         if (!empty($mime_type)) {
             if (true === $debug) {
                 return array('mime_type' => $mime_type, 'method' => 'mime_content_type');
             }
             return $mime_type;
         }
     }
     $mime_types = array('ai' => 'application/postscript', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'asc' => 'text/plain', 'asf' => 'video/x-ms-asf', 'asx' => 'video/x-ms-asf', 'au' => 'audio/basic', 'avi' => 'video/x-msvideo', 'bcpio' => 'application/x-bcpio', 'bin' => 'application/octet-stream', 'bmp' => 'image/bmp', 'bz2' => 'application/x-bzip2', 'cdf' => 'application/x-netcdf', 'chrt' => 'application/x-kchart', 'class' => 'application/octet-stream', 'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', 'csh' => 'application/x-csh', 'css' => 'text/css', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu', 'djvu' => 'image/vnd.djvu', 'dll' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'doc' => 'application/msword', 'dvi' => 'application/x-dvi', 'dxr' => 'application/x-director', 'eps' => 'application/postscript', 'etx' => 'text/x-setext', 'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv', 'gif' => 'image/gif', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'hdf' => 'application/x-hdf', 'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', 'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk', 'ief' => 'image/ief', 'iges' => 'model/iges', 'igs' => 'model/iges', 'img' => 'application/octet-stream', 'iso' => 'application/octet-stream', 'jad' => 'text/vnd.sun.j2me.app-descriptor', 'jar' => 'application/x-java-archive', 'jnlp' => 'application/x-java-jnlp-file', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', 'kar' => 'audio/midi', 'kil' => 'application/x-killustrator', 'kpr' => 'application/x-kpresenter', 'kpt' => 'application/x-kpresenter', 'ksp' => 'application/x-kspread', 'kwd' => 'application/x-kword', 'kwt' => 'application/x-kword', 'latex' => 'application/x-latex', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'm3u' => 'audio/x-mpegurl', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'mesh' => 'model/mesh', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime', 'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', 'ms' => 'application/x-troff-ms', 'msh' => 'model/mesh', 'mxu' => 'video/vnd.mpegurl', 'nc' => 'application/x-netcdf', 'odb' => 'application/vnd.oasis.opendocument.database', 'odc' => 'application/vnd.oasis.opendocument.chart', 'odf' => 'application/vnd.oasis.opendocument.formula', 'odg' => 'application/vnd.oasis.opendocument.graphics', 'odi' => 'application/vnd.oasis.opendocument.image', 'odm' => 'application/vnd.oasis.opendocument.text-master', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odt' => 'application/vnd.oasis.opendocument.text', 'ogg' => 'application/ogg', 'otg' => 'application/vnd.oasis.opendocument.graphics-template', 'oth' => 'application/vnd.oasis.opendocument.text-web', 'otp' => 'application/vnd.oasis.opendocument.presentation-template', 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', 'ott' => 'application/vnd.oasis.opendocument.text-template', 'pbm' => 'image/x-portable-bitmap', 'pdb' => 'chemical/x-pdb', 'pdf' => 'application/pdf', 'pgm' => 'image/x-portable-graymap', 'pgn' => 'application/x-chess-pgn', 'png' => 'image/png', 'pnm' => 'image/x-portable-anymap', 'ppm' => 'image/x-portable-pixmap', 'ppt' => 'application/vnd.ms-powerpoint', 'ps' => 'application/postscript', 'qt' => 'video/quicktime', 'ra' => 'audio/x-realaudio', 'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster', 'rgb' => 'image/x-rgb', 'rm' => 'audio/x-pn-realaudio', 'roff' => 'application/x-troff', 'rpm' => 'application/x-rpm', 'rtf' => 'text/rtf', 'rtx' => 'text/richtext', 'sgm' => 'text/sgml', 'sgml' => 'text/sgml', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'silo' => 'model/mesh', 'sis' => 'application/vnd.symbian.install', 'sit' => 'application/x-stuffit', 'skd' => 'application/x-koan', 'skm' => 'application/x-koan', 'skp' => 'application/x-koan', 'skt' => 'application/x-koan', 'smi' => 'application/smil', 'smil' => 'application/smil', 'snd' => 'audio/basic', 'so' => 'application/octet-stream', 'spl' => 'application/x-futuresplash', 'src' => 'application/x-wais-source', 'stc' => 'application/vnd.sun.xml.calc.template', 'std' => 'application/vnd.sun.xml.draw.template', 'sti' => 'application/vnd.sun.xml.impress.template', 'stw' => 'application/vnd.sun.xml.writer.template', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'swf' => 'application/x-shockwave-flash', 'sxc' => 'application/vnd.sun.xml.calc', 'sxd' => 'application/vnd.sun.xml.draw', 'sxg' => 'application/vnd.sun.xml.writer.global', 'sxi' => 'application/vnd.sun.xml.impress', 'sxm' => 'application/vnd.sun.xml.math', 'sxw' => 'application/vnd.sun.xml.writer', 't' => 'application/x-troff', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tgz' => 'application/x-gzip', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'torrent' => 'application/x-bittorrent', 'tr' => 'application/x-troff', 'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain', 'ustar' => 'application/x-ustar', 'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml', 'wav' => 'audio/x-wav', 'wax' => 'audio/x-ms-wax', 'wbmp' => 'image/vnd.wap.wbmp', 'wbxml' => 'application/vnd.wap.wbxml', 'wm' => 'video/x-ms-wm', 'wma' => 'audio/x-ms-wma', 'wml' => 'text/vnd.wap.wml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmls' => 'text/vnd.wap.wmlscript', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'wmv' => 'video/x-ms-wmv', 'wmx' => 'video/x-ms-wmx', 'wrl' => 'model/vrml', 'wvx' => 'video/x-ms-wvx', 'xbm' => 'image/x-xbitmap', 'xht' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml', 'xls' => 'application/vnd.ms-excel', 'xml' => 'text/xml', 'xpm' => 'image/x-xpixmap', 'xsl' => 'text/xml', 'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', 'zip' => 'application/zip');
     $ext = strtolower(array_pop(explode('.', $filename)));
     if (!empty($mime_types[$ext])) {
         if (true === $debug) {
             return array('mime_type' => $mime_types[$ext], 'method' => 'from_array');
         }
         return $mime_types[$ext];
     }
     if (true === $debug) {
         return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort');
     }
     return 'application/octet-stream';
 }
コード例 #21
0
ファイル: S3.php プロジェクト: awwthentic1234/hey
 public static function upload($file, $path = "", $fileName = NULL, $_mime = NULL)
 {
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $chk = array("bool" => true, 'result' => array(), "func" => "upload");
     //----------------------------------------------------------
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $file);
     finfo_close($finfo);
     if (!is_null($_mime)) {
         $mime = $_mime;
     }
     //----------------------------------------------------------
     $client = S3Client::factory(array('credentials' => array('key' => S3::$key, 'secret' => S3::$secret)));
     //----------------------------------------------------------
     try {
         $chk['result'] = $client->putObject(['Bucket' => S3::$bucket, 'Key' => $path . (!is_null($fileName) ? $fileName : basename($file)), 'Body' => fopen($file, r), 'ACL' => 'public-read', 'ContentType' => $mime]);
     } catch (S3Exception $e) {
         $chk['bool'] = false;
         $chk['message'] = "upload to s3 bucket: " . S3::$bucket . " failed!!!";
     }
     //----------------------------------------------------------
     return $chk;
 }
コード例 #22
0
ファイル: ExtensionManager.php プロジェクト: clops/core
 public function getInfo()
 {
     $extensionsDir = $this->getExtensionsDir();
     $dirs = array_diff(scandir($extensionsDir), ['.', '..']);
     $extensions = [];
     $installed = json_decode(file_get_contents(public_path('vendor/composer/installed.json')), true);
     foreach ($dirs as $dir) {
         if (file_exists($manifest = $extensionsDir . '/' . $dir . '/composer.json')) {
             $extension = json_decode(file_get_contents($manifest), true);
             if (empty($extension['name'])) {
                 continue;
             }
             if (isset($extension['extra']['flarum-extension']['icon'])) {
                 $icon =& $extension['extra']['flarum-extension']['icon'];
                 if ($file = array_get($icon, 'image')) {
                     $file = $extensionsDir . '/' . $dir . '/' . $file;
                     if (file_exists($file)) {
                         $mimetype = pathinfo($file, PATHINFO_EXTENSION) === 'svg' ? 'image/svg+xml' : finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
                         $data = file_get_contents($file);
                         $icon['backgroundImage'] = 'url(\'data:' . $mimetype . ';base64,' . base64_encode($data) . '\')';
                     }
                 }
             }
             foreach ($installed as $package) {
                 if ($package['name'] === $extension['name']) {
                     $extension['version'] = $package['version'];
                 }
             }
             $extension['id'] = $dir;
             $extensions[$dir] = $extension;
         }
     }
     return $extensions;
 }
コード例 #23
0
ファイル: Fso.class.php プロジェクト: noikiy/dophin
 /**
  * 获取文件的mime-type
  * @param string $file
  */
 public static function getMimeType($file)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $type = finfo_file($finfo, $file);
     finfo_close($finfo);
     return $type;
 }
コード例 #24
0
ファイル: Upload.php プロジェクト: Bruno17/bloX-Xedit
 /**
  * Returns (if possible) the mimetype of the given file
  *
  * @param string $file
  * @param array $options
  */
 public function mime($file, $options = array())
 {
     $file = realpath($file);
     $options = array_merge(array('default' => null, 'extension' => strtolower(pathinfo($file, PATHINFO_EXTENSION))), $options);
     $mime = null;
     if (function_exists('finfo_open') && ($f = finfo_open(FILEINFO_MIME, getenv('MAGIC')))) {
         $mime = finfo_file($f, $file);
         finfo_close($f);
     }
     if (!$mime && in_array($options['extension'], array('gif', 'jpg', 'jpeg', 'png'))) {
         $image = getimagesize($file);
         if (!empty($image['mime'])) {
             $mime = $image['mime'];
         }
     }
     if (!$mime && $options['default']) {
         $mime = $options['default'];
     }
     if ((!$mime || $mime == 'application/octet-stream') && $options['extension']) {
         static $mimes;
         if (!$mimes) {
             $mimes = parse_ini_file(pathinfo(__FILE__, PATHINFO_DIRNAME) . '/MimeTypes.ini');
         }
         if (!empty($mimes[$options['extension']])) {
             return $mimes[$options['extension']];
         }
     }
     return $mime;
 }
コード例 #25
0
 public function fileimportAction(Request $request)
 {
     $filetype = filter_var($request->get('type'), FILTER_SANITIZE_STRING);
     $uploadedFile = $request->files->get('upfile');
     if (!isset($uploadedFile)) {
         return new Response('No file');
     }
     $origname = $uploadedFile->getClientOriginalName();
     $origext = $uploadedFile->getClientOriginalExtension();
     $filename = $uploadedFile->getPathname();
     if (function_exists("finfo_open")) {
         // return mime type ala mimetype extension
         $finfo = finfo_open(FILEINFO_MIME);
         // check to see if the mime-type starts with 'text'
         $is_text = substr(finfo_file($finfo, $filename), 0, 4) == 'text' || substr(finfo_file($finfo, $filename), 0, 15) == "application/xml";
         if (!$is_text) {
             return new Response('Bad file');
         }
     }
     if ($filetype == "octgn" || $filetype == "auto" && $origext == "o8d") {
         $parse = $this->parseOctgnImport(file_get_contents($filename));
     } else {
         $parse = $this->parseTextImport(file_get_contents($filename));
     }
     return $this->forward('NetrunnerdbBuilderBundle:Builder:save', array('name' => $origname, 'content' => json_encode($parse['content']), 'description' => $parse['description']));
 }
コード例 #26
0
 /**
  * Returns the MIME content type of an uploaded file.
  * @return string|NULL
  */
 public function getContentType()
 {
     if ($this->isOk() && $this->type === NULL) {
         $this->type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->tmpName);
     }
     return $this->type;
 }
コード例 #27
0
 /**
  * @desc Retrieve the corresponding MIME type, if one exists
  * @param String $file File Name (relative location such as "image_test.jpg" or full "http://site.com/path/to/image_test.jpg")
  * @return String $MIMEType - The type of the file passed in the argument
  */
 public function getMimeType($file = NULL)
 {
     if (is_file($file)) {
         /**
          * Attempts to retrieve file info from FINFO
          * If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
          * If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
          * If all else fails, just return application/octet-stream
          */
         if (!function_exists("finfo_open")) {
             $extension = $this->getExtension($file);
             if (array_key_exists($extension, $this->mimeTypes)) {
                 return $this->mimeTypes[$extension];
             } else {
                 if (function_exists("mime_content_type")) {
                     $type = mime_content_type($file);
                     return !empty($type) ? $type : "application/octet-stream";
                 } else {
                     return "application/octet-stream";
                 }
             }
         } else {
             $finfo = finfo_open(FILEINFO_MIME);
             $MIMEType = finfo_file($finfo, $file);
             finfo_close($finfo);
             return $MIMEType;
         }
     } else {
         return "##INVALID_FILE##FILE=" . $file . "##";
     }
 }
コード例 #28
0
ファイル: Mime.php プロジェクト: sfie/pimcore
 /**
  * @param $file
  * @param null $filename
  * @return mixed|string
  * @throws \Exception
  */
 public static function detect($file, $filename = null)
 {
     if (!file_exists($file)) {
         throw new \Exception("File " . $file . " doesn't exist");
     }
     if (!$filename) {
         $filename = basename($file);
     }
     // check for an extension mapping first
     if ($filename) {
         $extension = \Pimcore\File::getFileExtension($filename);
         if (array_key_exists($extension, self::$extensionMapping)) {
             return self::$extensionMapping[$extension];
         }
     }
     // check with fileinfo, if there's no extension mapping
     $finfo = finfo_open(FILEINFO_MIME);
     $type = finfo_file($finfo, $file);
     finfo_close($finfo);
     if ($type !== false && !empty($type)) {
         if (strstr($type, ';')) {
             $type = substr($type, 0, strpos($type, ';'));
         }
         return $type;
     }
     // return default mime-type if we're unable to detect it
     return "application/octet-stream";
 }
コード例 #29
0
ファイル: Utils.php プロジェクト: Konosprod/ciconia
 public static function getMimetype($path)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $path);
     finfo_close($finfo);
     return $mime;
 }
コード例 #30
0
ファイル: File.php プロジェクト: efaby/postulacion
 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.");
     }
 }