Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
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
1
Merge Requests
1
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-micro
Commits
1d22a338
Commit
1d22a338
authored
Nov 19, 2020
by
jiangkebao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载远程文件
parent
f68443a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
functions.php
src/functions.php
+36
-0
No files found.
src/functions.php
View file @
1d22a338
...
...
@@ -813,4 +813,40 @@ if (!function_exists('get_images_url')) {
preg_match
(
'/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i'
,
$str
,
$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
;;
}
}
\ 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