-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johnny
committed
Nov 29, 2016
1 parent
4113c36
commit b94d9bc
Showing
9 changed files
with
2,101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/.idea/ | ||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
##### 说明 | ||
|
||
本扩展为yangyifan/upload的分支,仅为解决在开发过这种遇到的问题: | ||
* 原扩展没有release版本,导致开发时composer.json未设置"minimum-stability": "dev"时候,不能正常安装的问题,即便设置了 "minimum-stability": "dev",直接使用composer update时会使其他依赖包也强制更新到了dev-master版本,带来不稳定因素。 | ||
|
||
|
||
##### 安装 | ||
|
||
* composer require "ikodota/upload" 。 | ||
* 添加 UploadServiceProvider 到您项目 config/app.php 中的 providers 部分: Yangyifan\Upload\UploadServiceProvider。 | ||
* 支持七牛,upyun,oss。 | ||
* 完成按照官方 ``` Storage ``` 来扩展。所以不需要修改代码,只需要新增配置文件信息,就可以替换任何一种存储引擎。 | ||
|
||
###### 开始 | ||
|
||
* use Storage | ||
|
||
``` | ||
use Storage; | ||
``` | ||
|
||
* 示例代码 | ||
|
||
``` | ||
$image = "11/22/33/7125_yangxiansen.jpg"; | ||
$image2 = "111.png"; | ||
$image3 = "2.txt"; | ||
$drive = \Storage::drive('oss'); //选择oss上传引擎 | ||
dump($drive->getMetadata($image2)); //判断文件是否存在 | ||
dump($drive->has($image2)); //判断文件是否存在 | ||
dump($drive->listContents('')); //列出文件列表 | ||
dump($drive->getSize($image2)); //获得图片大小 | ||
dump($drive->getMimetype($image2)); //获得图片mime类型 | ||
dump($drive->getTimestamp($image2)); //获得图片上传时间戳 | ||
dump($drive->read($image3)); //获得文件信息 | ||
dump($drive->readStream($image3)); //获得文件信息 | ||
dump($drive->rename($image3, '4.txt/')); //重命名文件 | ||
dump($drive->copy('4.txt/', '/txt/5.txt')); //复制文件 | ||
dump($drive->delete('/txt/5.txt')); //删除文件 | ||
dump ($drive->write("/txt/4.txt", $drive->read("/4.txt")) ); //上传文件 | ||
dump($drive->write("/test2.txt", "111222")); //上传文件 | ||
dump($drive->deleteDir('txt/')); //删除文件夹 | ||
dump($drive->createDir('test3/')); //创建文件夹 | ||
$handle = fopen('/tmp/email.png', 'r'); | ||
dump ($drive->writeStream("/write/test3.png", $handle ) ); //上传文件(文件流方式) | ||
dump ($drive->writeStream("/test6.png", $drive->readStream('/write/test3.png') ) ); //上传文件(文件流方式) | ||
``` | ||
|
||
|
||
###### 配置信息 | ||
|
||
``` | ||
'qiniu' => [ | ||
'driver' => 'qiniu', | ||
'domain' => '',//你的七牛域名 | ||
'access_key' => '',//AccessKey | ||
'secret_key' => '',//SecretKey | ||
'bucket' => '',//Bucket名字 | ||
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http | ||
], | ||
'upyun' => [ | ||
'driver' => 'upyun', | ||
'domain' => '',//你的upyun域名 | ||
'username' => '',//UserName | ||
'password' => '',//Password | ||
'bucket' => '',//Bucket名字 | ||
'timeout' => 130,//超时时间 | ||
'endpoint' => null,//线路 | ||
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http | ||
], | ||
'oss' => [ | ||
'driver' => 'oss', | ||
'accessKeyId' => '', | ||
'accessKeySecret' => '', | ||
'endpoint' => '', | ||
'isCName' => false, | ||
'securityToken' => null, | ||
'bucket' => '', | ||
'timeout' => '5184000', | ||
'connectTimeout' => '10', | ||
'transport' => 'http',//如果支持https,请填写https,如果不支持请填写http | ||
'max_keys' => 1000,//max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于1000 | ||
], | ||
], | ||
``` | ||
|
||
###### 其他 | ||
|
||
* 如果需要支持其他的上传引擎,请联系我,如果我有空,我会去扩展,希望这个能帮助大家开发,谢谢,有问题pr我,或者邮件联系我,我的邮箱是:[email protected](原作者邮箱:[email protected])。 | ||
* 下一步计划将完成单元测试。 | ||
|
||
###### 协议 | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "ikodota/upload", | ||
"description": "上传 SDK for Laravel", | ||
"keywords": ["upload", "laravel", "sdk", "qiniu", "upyun", "oss"], | ||
"require": { | ||
"qiniu/php-sdk": "v7.0.*", | ||
"aliyuncs/oss-sdk-php" : "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Ikodota\\Upload\\": "src/" | ||
} | ||
}, | ||
|
||
"license": "MIT", | ||
"minimum-stability" : "dev", | ||
"authors": [ | ||
{ | ||
"name": "yangyifan", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "ikodota", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
// +---------------------------------------------------------------------- | ||
// | date: 2016-03-04 | ||
// +---------------------------------------------------------------------- | ||
// | FileFunction.php: 文件相关方法 | ||
// +---------------------------------------------------------------------- | ||
// | Author: yangyifan <[email protected]> | ||
// +---------------------------------------------------------------------- | ||
|
||
namespace Ikodota\Upload\Functions; | ||
|
||
|
||
class FileFunction | ||
{ | ||
|
||
/** | ||
* 获得文件mime_type | ||
* | ||
* @param $file | ||
* @return bool|mixed | ||
* @author yangyifan <[email protected]> | ||
*/ | ||
public static function getFileMimeType($file) | ||
{ | ||
$finfo = finfo_open(FILEINFO_MIME_TYPE); | ||
if ($finfo) { | ||
$mime_type = finfo_file($finfo, $file); | ||
finfo_close($finfo); | ||
return $mime_type; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* 获得一个临时文件 | ||
* | ||
* @return string | ||
* @author yangyifan <[email protected]> | ||
*/ | ||
public static function getTmpFile() | ||
{ | ||
$tmpfname = tempnam("/tmp", "dir"); | ||
chmod($tmpfname, 0777); | ||
return $tmpfname; | ||
} | ||
|
||
/** | ||
* 删除一个临时文件 | ||
* | ||
* @param $file_name | ||
* @return bool | ||
* @author yangyifan <[email protected]> | ||
*/ | ||
public static function deleteTmpFile($file_name) | ||
{ | ||
return unlink($file_name); | ||
} | ||
} |
Oops, something went wrong.