Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
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
Kulya
TelegramBot
Commits
096bd751
Unverified
Commit
096bd751
authored
Aug 27, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make downloadFile method more robust.
parent
51318946
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
Request.php
src/Request.php
+13
-13
No files found.
src/Request.php
View file @
096bd751
...
...
@@ -242,31 +242,31 @@ class Request
*/
public
static
function
downloadFile
(
File
$file
)
{
$path
=
$file
->
getFilePath
();
//Create the directory
$
loc_path
=
self
::
$telegram
->
getDownloadPath
()
.
'/'
.
$path
;
$dirname
=
dirname
(
$loc_path
);
if
(
!
is_dir
(
$dirname
)
&&
!
mkdir
(
$dirname
,
0755
,
true
))
{
throw
new
TelegramException
(
'Directory '
.
$
dirname
.
' can\'t be created'
);
$
tg_file_
path
=
$file
->
getFilePath
();
$file_path
=
self
::
$telegram
->
getDownloadPath
()
.
'/'
.
$tg_file_path
;
$
file_dir
=
dirname
(
$file_path
)
;
//For safety reasons, first try to create the directory, then check that it exists.
//This is in case some other process has created the folder in the meantime.
if
(
!
@
mkdir
(
$file_dir
,
0755
,
true
)
&&
!
is_dir
(
$file_dir
))
{
throw
new
TelegramException
(
'Directory '
.
$
file_dir
.
' can\'t be created'
);
}
$debug_handle
=
TelegramLog
::
getDebugLogTempStream
();
try
{
self
::
$client
->
get
(
'/file/bot'
.
self
::
$telegram
->
getApiKey
()
.
'/'
.
$path
,
[
'debug'
=>
$debug_handle
,
'sink'
=>
$
loc
_path
]
'/file/bot'
.
self
::
$telegram
->
getApiKey
()
.
'/'
.
$
tg_file_
path
,
[
'debug'
=>
$debug_handle
,
'sink'
=>
$
file
_path
]
);
return
filesize
(
$file_path
)
>
0
;
}
catch
(
RequestException
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
finally
{
//Logging verbose debug output
TelegramLog
::
endDebugLogTempStream
(
"Verbose HTTP File Download Request output:
\n
%s
\n
"
);
}
return
(
filesize
(
$loc_path
)
>
0
);
}
/**
...
...
@@ -330,7 +330,7 @@ class Request
*/
private
static
function
ensureNonEmptyData
(
array
$data
)
{
if
(
empty
(
$data
)
)
{
if
(
count
(
$data
)
===
0
)
{
throw
new
TelegramException
(
'Data is empty!'
);
}
}
...
...
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