Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
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
outils
question2answer
Commits
e0826445
Commit
e0826445
authored
Apr 25, 2015
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored some byte handling operations
parent
02f8514d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
33 deletions
+55
-33
upload.php
qa-include/app/upload.php
+2
-13
qa-base.php
qa-include/qa-base.php
+24
-10
image.php
qa-include/util/image.php
+1
-10
BaseTest.php
qa-tests/BaseTest.php
+28
-0
No files found.
qa-include/app/upload.php
View file @
e0826445
...
...
@@ -33,22 +33,11 @@
{
if
(
qa_to_override
(
__FUNCTION__
))
{
$args
=
func_get_args
();
return
qa_call_override
(
__FUNCTION__
,
$args
);
}
$mindb
=
16777215
;
// from MEDIUMBLOB column type
$minphp
=
trim
(
ini_get
(
'upload_max_filesize'
));
switch
(
strtolower
(
substr
(
$minphp
,
-
1
)))
{
case
'g'
:
$minphp
*=
1024
;
// fall-through
case
'm'
:
$minphp
*=
1024
;
// fall-through
case
'k'
:
$minphp
*=
1024
;
}
$minphp
=
convert_to_bytes
(
substr
(
$minphp
,
-
1
),
$minphp
);
return
min
(
$mindb
,
$minphp
);
return
min
(
16777215
,
$minphp
);
// 16777215 from MEDIUMBLOB column type
}
...
...
qa-include/qa-base.php
View file @
e0826445
...
...
@@ -1064,21 +1064,35 @@
if
(
!
is_numeric
(
$unit
))
{
$postmaxsize
=
substr
(
$postmaxsize
,
0
,
-
1
);
}
switch
(
strtoupper
(
$unit
))
{
// Gets an integer value that can be compared against the size of the HTTP request
case
'G'
:
$postmaxsize
*=
1024
;
// fall-through
case
'M'
:
$postmaxsize
*=
1024
;
// fall-through
case
'K'
:
$postmaxsize
*=
1024
;
}
// Gets an integer value that can be compared against the size of the HTTP request
$postmaxsize
=
convert_to_bytes
(
$unit
,
$postmaxsize
);
return
$_SERVER
[
'CONTENT_LENGTH'
]
>
$postmaxsize
;
}
}
/**
* Turns a numeric value and a unit (g/m/k) into bytes
* @param string $unit One of 'g', 'm', 'k'. It is case insensitive
* @param int $value The value to turn into bytes
* @return int The amount of bytes the unit and the value represent. If the unit is not one of 'g', 'm' or 'k' then
* the original value is returned
*/
function
convert_to_bytes
(
$unit
,
$value
)
{
switch
(
strtolower
(
$unit
))
{
case
'g'
:
return
$value
*
1073741824
;
case
'm'
:
return
$value
*
1048576
;
case
'k'
:
return
$value
*
1024
;
default
:
return
$value
;
}
}
function
qa_is_http_post
()
/*
Return true if we are responding to an HTTP POST request
...
...
qa-include/util/image.php
View file @
e0826445
...
...
@@ -45,16 +45,7 @@
if
(
function_exists
(
'memory_get_usage'
))
{
$gotbytes
=
trim
(
@
ini_get
(
'memory_limit'
));
switch
(
strtolower
(
substr
(
$gotbytes
,
-
1
)))
{
case
'g'
:
$gotbytes
*=
1024
;
// fall-through
case
'm'
:
$gotbytes
*=
1024
;
// fall-through
case
'k'
:
$gotbytes
*=
1024
;
}
$gotbytes
=
convert_to_bytes
(
substr
(
$gotbytes
,
-
1
),
$gotbytes
);
if
(
$gotbytes
>
0
)
{
// otherwise we clearly don't know our limit
$gotbytes
=
(
$gotbytes
-
memory_get_usage
())
*
0.9
;
// safety margin of 10%
...
...
qa-tests/BaseTest.php
View file @
e0826445
...
...
@@ -22,4 +22,32 @@ class BaseTest extends PHPUnit_Framework_TestCase
$test
=
qa_js
(
true
,
true
);
$this
->
assertSame
(
"'true'"
,
$test
);
}
public
function
test__convert_to_bytes
()
{
$test
=
convert_to_bytes
(
'k'
,
100
);
$this
->
assertSame
(
102400
,
$test
);
$test
=
convert_to_bytes
(
'm'
,
100
);
$this
->
assertSame
(
104857600
,
$test
);
$test
=
convert_to_bytes
(
'g'
,
100
);
$this
->
assertSame
(
107374182400
,
$test
);
$test
=
convert_to_bytes
(
'K'
,
100
);
$this
->
assertSame
(
102400
,
$test
);
$test
=
convert_to_bytes
(
'M'
,
100
);
$this
->
assertSame
(
104857600
,
$test
);
$test
=
convert_to_bytes
(
'G'
,
100
);
$this
->
assertSame
(
107374182400
,
$test
);
$test
=
convert_to_bytes
(
''
,
100
);
$this
->
assertSame
(
100
,
$test
);
$test
=
convert_to_bytes
(
'k'
,
1024
);
$this
->
assertSame
(
1048576
,
$test
);
}
}
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