Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
sinan
mongo-php-library
Commits
ebf903d6
Commit
ebf903d6
authored
Jan 07, 2016
by
Will Banfield
Committed by
Jeremy Mikola
Mar 14, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Straighten out abort method
parent
9709007b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
17 deletions
+16
-17
GridFsUpload.php
src/GridFS/GridFsUpload.php
+16
-17
No files found.
src/GridFS/GridFsUpload.php
View file @
ebf903d6
...
...
@@ -107,11 +107,8 @@ class GridFsUpload
throw
new
UnexpectedTypeException
(
'stream'
,
$source
);
}
else
{
$streamMetadata
=
stream_get_meta_data
(
$source
);
}
if
(
!
is_readable
(
$streamMetadata
[
'uri'
]))
{
// throw new InvalidArgumentException("stream not readable");
//issue being that php's is_readable reports native streams as not readable like php://temp
}
while
(
$data
=
fread
(
$source
,
$this
->
chunkSize
))
{
while
(
$data
=
$this
->
readChunk
(
$source
))
{
$this
->
insertChunk
(
$data
);
}
return
$this
->
fileCollectionInsert
();
...
...
@@ -198,12 +195,7 @@ class GridFsUpload
}
$toUpload
=
[
"files_id"
=>
$this
->
file
[
'_id'
],
"n"
=>
$this
->
chunkOffset
,
"data"
=>
new
\MongoDB\BSON\Binary
(
$data
,
\MongoDB\BSON\Binary
::
TYPE_GENERIC
)];
hash_update
(
$this
->
ctx
,
$data
);
try
{
$this
->
collectionsWrapper
->
chunkInsert
(
$toUpload
);
}
catch
(
\MongoDB\Exception
$e
){
$this
->
abort
();
throw
$e
;
}
$this
->
length
+=
strlen
(
$data
);
$this
->
chunkOffset
++
;
}
...
...
@@ -214,12 +206,7 @@ class GridFsUpload
}
$md5
=
hash_final
(
$this
->
ctx
);
$this
->
file
=
array_merge
(
$this
->
file
,
[
'length'
=>
$this
->
length
,
'md5'
=>
$md5
]);
try
{
$this
->
collectionsWrapper
->
fileInsert
(
$this
->
file
);
}
catch
(
\MongoDB\Exception
$e
){
$this
->
abort
();
throw
$e
;
}
return
$this
->
file
[
'_id'
];
}
//from: http://stackoverflow.com/questions/3656713/how-to-get-current-time-in-milliseconds-in-php
...
...
@@ -228,4 +215,16 @@ class GridFsUpload
$comps
=
explode
(
' '
,
$microtime
);
return
sprintf
(
'%d%03d'
,
$comps
[
1
],
$comps
[
0
]
*
1000
);
}
private
function
readChunk
(
$source
)
{
$data
;
try
{
$data
=
fread
(
$source
,
$this
->
chunkSize
);
}
catch
(
Exception
$e
)
{
$this
->
abort
();
throw
$e
;
}
return
$data
;
}
}
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