承接 peterpostmann/fileuri 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

peterpostmann/fileuri

Composer 安装命令:

composer require peterpostmann/fileuri

包简介

Returns a file uri from a (relative) path

README 文档

README

Software License Build Status

Returns a file uri from a (relative) path

Install

Via Composer

composer require peterpostmann/fileuri

If you dont want to use composer just copy the fileuri.php file and include it into your project.

Why

This function can be used to create RFC3986 complient file URIs and build protocol agnostic functions.

function parseReference($ref)
{
    list($prefix, $path) = explode('://', $ref, 2);
    return [$prefix, $path];
}

var_dump(parseReference('https://server.tld/path/ressource.ext'));
var_dump(parseReference('file:///path/to/file.ext'));

The above example will output:


array (size=2)
  0 => string 'https' (length=5)
  1 => string 'server.tld/path/ressource.ext' (length=29)


array (size=2)
  0 => string 'file' (length=4)
  1 => string '/path/to/file.ext (length=17)

If you want to examine URIs of multiple protocols this cannot be done easily because PHP does not return rfc3986 compliant URIs for files. PHP returns different formats depending on the file location and platform (http://php.net/manual/en/wrappers.file.php)

use Sabre\Uri;

function parseReference($uri)
{
    return Uri\parse($uri);
}

Usage

use function peterpostmann\fileuri;

string fileuri ( string path [, string basePath] ) 

Example

Sample Output

use function peterpostmann\fileuri;

// Absolute Path
echo fileuri('/path/to/file.ext');
echo fileuri('C:\path\to\winfile.ext');
echo fileuri('\\\\smbserver\share\path\to\winfile.ext');

// Relative Path with base path
echo fileuri('relative/path/to/file.ext', '/');
echo fileuri('fileInCwd.ext','C:\testfolder);

// Path that is already a URI
echo fileuri('file:///path/to/file.ext');

The above example will output:


file:///path/to/file.ext
file:///C:/path/to/winfile.ext
file:///C:/path/to/winfile.ext
file://smbserver/share/path/to/winfile.ext
file:///relative/path/to/file.ext
file:///C:/testfolder/fileInCwd.ext
file:///path/to/file.ext

Error Output

The function returns false if a relative path is given without a base path.

use function peterpostmann\fileuri;

// Relative Path without base path
var_dump(fileuri('relative/path/to/file.ext'));

The above example will output:


boolean false

Usage with file functions

use function peterpostmann\fileuri;

// Absolute Path
$uri = fileuri('/path/to/file.ext');

var_dump(file_get_contents(urldecode($uri)));

file_get_contents does not normalize urls, therefore file URIs cannot be used directly.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 257
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 4
  • 推荐数: 2

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固