mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
[php,cmd:open] fix #1586 RFC7233 violation, add commandsOptions.open.method
- php:connector - range request supports on GET request only
- js - add an option `commandsOptions.open.method`
```javascript
open : {
// HTTP method that request to the connector when item URL is not valid URL.
// If you set to "get" will be displayed request parameter in the browser's location field
// so if you want to conceal its parameters should be given "post".
// Nevertheless, please specify "get" if you want to enable the partial request by HTTP Range header.
method : 'post'
},
```
This commit is contained in:
@@ -27,7 +27,13 @@ class elFinderConnector {
|
||||
**/
|
||||
protected $header = 'Content-Type: application/json';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP request method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reqMethod = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -38,6 +44,7 @@ class elFinderConnector {
|
||||
public function __construct($elFinder, $debug=false) {
|
||||
|
||||
$this->elFinder = $elFinder;
|
||||
$this->reqMethod = strtoupper($_SERVER["REQUEST_METHOD"]);
|
||||
if ($debug) {
|
||||
$this->header = 'Content-Type: text/html; charset=utf-8';
|
||||
}
|
||||
@@ -50,8 +57,8 @@ class elFinderConnector {
|
||||
* @author Dmitry (dio) Levashov
|
||||
**/
|
||||
public function run() {
|
||||
$isPost = $_SERVER["REQUEST_METHOD"] == 'POST';
|
||||
$src = $_SERVER["REQUEST_METHOD"] == 'POST' ? $_POST : $_GET;
|
||||
$isPost = $this->reqMethod === 'POST';
|
||||
$src = $isPost ? $_POST : $_GET;
|
||||
if ($isPost && !$src && $rawPostData = @file_get_contents('php://input')) {
|
||||
// for support IE XDomainRequest()
|
||||
$parts = explode('&', $rawPostData);
|
||||
@@ -151,7 +158,9 @@ class elFinderConnector {
|
||||
if (isset($data['pointer'])) {
|
||||
$toEnd = true;
|
||||
$fp = $data['pointer'];
|
||||
if (elFinder::isSeekableStream($fp) && (array_search('Accept-Ranges: none', headers_list()) === false)) {
|
||||
if (($this->reqMethod === 'GET' || $this->reqMethod === 'HEAD')
|
||||
&& elFinder::isSeekableStream($fp)
|
||||
&& (array_search('Accept-Ranges: none', headers_list()) === false)) {
|
||||
header('Accept-Ranges: bytes');
|
||||
$psize = null;
|
||||
if (!empty($_SERVER['HTTP_RANGE'])) {
|
||||
@@ -201,13 +210,16 @@ class elFinderConnector {
|
||||
// client disconnect should abort
|
||||
ignore_user_abort(false);
|
||||
|
||||
if ($toEnd) {
|
||||
fpassthru($fp);
|
||||
} else {
|
||||
$out = fopen('php://output', 'wb');
|
||||
stream_copy_to_stream($fp, $out, $psize);
|
||||
fclose($out);
|
||||
if ($reqMethod !== 'HEAD') {
|
||||
if ($toEnd) {
|
||||
fpassthru($fp);
|
||||
} else {
|
||||
$out = fopen('php://output', 'wb');
|
||||
stream_copy_to_stream($fp, $out, $psize);
|
||||
fclose($out);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['volume'])) {
|
||||
$data['volume']->close($data['pointer'], $data['info']['hash']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user