Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-rpc
Commits
35022387
Commit
35022387
authored
Nov 19, 2020
by
jiangkebao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master_download_file' into test
parents
85d38a53
ed5f9795
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
functions.php
src/functions.php
+58
-0
No files found.
src/functions.php
View file @
35022387
...
@@ -813,4 +813,62 @@ if (!function_exists('get_images_url')) {
...
@@ -813,4 +813,62 @@ if (!function_exists('get_images_url')) {
preg_match
(
'/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i'
,
$str
,
$match
);
preg_match
(
'/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i'
,
$str
,
$match
);
return
$match
;
return
$match
;
}
}
}
if
(
!
function_exists
(
'download_file'
))
{
/**
* 下载远程文件
* @param $url 远程文件路径
* @param null $path 系统保存路径
* @return string
*/
function
download_file
(
$url
,
$path
=
null
)
{
$filename
=
trim
(
pathinfo
(
$url
,
PATHINFO_FILENAME
));
$ext
=
strtolower
(
pathinfo
(
$url
,
PATHINFO_EXTENSION
));
$filename
=
"
$filename
.
$ext
"
;
$root
=
config
(
'server.settings.document_root'
,
BASE_PATH
.
'/public'
);
$path
=
$path
?
$path
:
'/download/files'
;
$savePath
=
$root
.
$path
;
if
(
!
is_dir
(
$savePath
))
{
// 判断路径是否存在,不存在,则创建
mkdir
(
$savePath
,
0777
,
true
);
}
$filePath
=
$savePath
.
'/'
.
$filename
;
if
(
!
file_exists
(
$filePath
))
{
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
30
);
$file
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
$resource
=
fopen
(
$filePath
,
'a'
);
fwrite
(
$resource
,
$file
);
fclose
(
$resource
);
}
return
$path
.
'/'
.
$filename
;;
}
}
if
(
!
function_exists
(
'download_file_stream'
))
{
/**文件流保存到本地
* @param $fileStream 文件流
* @param null $path 保存路径
* @return string
*/
function
download_file_stream
(
$fileStream
,
$path
=
null
)
{
$root
=
config
(
'server.settings.document_root'
,
BASE_PATH
.
'/public'
);
$path
=
$path
?
$path
:
'/download/files'
;
$savePath
=
$root
.
$path
;
if
(
!
is_dir
(
$savePath
))
{
// 判断路径是否存在,不存在,则创建
mkdir
(
$savePath
,
0777
,
true
);
}
$fileName
=
'/'
.
date
(
'YmdHis'
)
.
'track'
.
'.pdf'
;
file_put_contents
(
$savePath
.
$fileName
,
base64_decode
(
$fileStream
),
1
);
return
$path
.
$fileName
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment