|
@@ -7,6 +7,7 @@ class Local
|
|
|
public function init($config)
|
|
|
{
|
|
|
$this->config = $config;
|
|
|
+
|
|
|
}
|
|
|
public function upload($type, $source, $dest, $chunk, $upload)
|
|
|
{
|
|
@@ -33,15 +34,18 @@ class Local
|
|
|
$files = scandir($dir);
|
|
|
$num = count($files) - 2;
|
|
|
if ($num == $chunk['total']) {
|
|
|
- $blob = '';
|
|
|
- foreach ($files as $k => $v) {
|
|
|
- if (strstr($v, '.blob')) {
|
|
|
+ $out = fopen($chunk['file'], 'ab');
|
|
|
+ natsort($files);
|
|
|
+ foreach ($files as $v) {
|
|
|
+ if (pathinfo($v, PATHINFO_EXTENSION) === 'blob') {
|
|
|
$temp = $dir . '/' . $v;
|
|
|
- $blob .= file_get_contents($temp);
|
|
|
- @unlink($temp);
|
|
|
+ $in = fopen($temp, 'rb');
|
|
|
+ stream_copy_to_stream($in, $out); // 边读边写
|
|
|
+ fclose($in);
|
|
|
+ @unlink($temp); // 删除分片
|
|
|
}
|
|
|
}
|
|
|
- file_put_contents($chunk['file'], $blob);
|
|
|
+ fclose($out);
|
|
|
@rmdir($dir);
|
|
|
$file = $chunk['file'];
|
|
|
} else {
|
|
@@ -51,6 +55,7 @@ class Local
|
|
|
return '';
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
$after = $upload->after();
|
|
|
if ($after) {
|
|
|
$tool = Dever::load(Tool::class)->get()->cover(true);
|
|
@@ -67,7 +72,7 @@ class Local
|
|
|
private function url($file)
|
|
|
{
|
|
|
$dest = str_replace(Dever::data() . DEVER_PROJECT . '/', '', $file);
|
|
|
- if ($this->config['host']) {
|
|
|
+ if (isset($this->config['host']) && $this->config['host']) {
|
|
|
return $this->config['host'] . $dest;
|
|
|
}
|
|
|
return Dever::host() . 'data/' . DEVER_PROJECT . '/' . $dest;
|