优化文件上传
This commit is contained in:
parent
f770855131
commit
3722bf3bbc
@ -117,16 +117,15 @@ class File extends BasicApi
|
|||||||
$ext = $ext[count($ext) - 1];
|
$ext = $ext[count($ext) - 1];
|
||||||
$fileUrl = "{$path}/{$fileName}-{$i}.{$ext}";
|
$fileUrl = "{$path}/{$fileName}-{$i}.{$ext}";
|
||||||
$site_url = FileService::getFileUrl($fileUrl, 'local');
|
$site_url = FileService::getFileUrl($fileUrl, 'local');
|
||||||
// $blob = file_get_contents($site_url);
|
$blob = file_get_contents($site_url);
|
||||||
$blob .= file_get_contents($site_url);
|
// $blob .= file_get_contents($site_url);
|
||||||
|
|
||||||
$fileList[] = env('root_path') . $fileUrl;
|
$fileList[] = env('root_path') . $fileUrl;
|
||||||
|
$result = FileService::$type($path2, $blob, true);
|
||||||
// $result = FileService::$type($path2, $blob);
|
unset($blob);
|
||||||
// unset($blob);
|
unset($site_url);
|
||||||
// unset($site_url);
|
unset($fileUrl);
|
||||||
}
|
}
|
||||||
$result = FileService::$type($path2, $blob);
|
// $result = FileService::$type($path2, $blob);
|
||||||
$fileData['size'] = $data['totalSize'];
|
$fileData['size'] = $data['totalSize'];
|
||||||
$fileData['path_name'] = $result['key'];
|
$fileData['path_name'] = $result['key'];
|
||||||
$fileData['file_url'] = $result['url'];
|
$fileData['file_url'] = $result['url'];
|
||||||
@ -135,10 +134,11 @@ class File extends BasicApi
|
|||||||
!isset($data['taskCode']) && $data['taskCode'] = '';
|
!isset($data['taskCode']) && $data['taskCode'] = '';
|
||||||
$fileResult = \app\common\Model\File::createFile($data['projectCode'], $fileData);
|
$fileResult = \app\common\Model\File::createFile($data['projectCode'], $fileData);
|
||||||
|
|
||||||
|
unset($fileData);
|
||||||
unset($info);
|
unset($info);
|
||||||
//文件碎片移除
|
//文件碎片移除
|
||||||
foreach ($fileList as $file) {
|
foreach ($fileList as $file) {
|
||||||
unlink($file);
|
@unlink($file);
|
||||||
}
|
}
|
||||||
$fileInfo = \app\common\Model\File::where(['code' => $fileResult['code']])->find();
|
$fileInfo = \app\common\Model\File::where(['code' => $fileResult['code']])->find();
|
||||||
if ($data['taskCode']) {
|
if ($data['taskCode']) {
|
||||||
|
@ -305,12 +305,12 @@ class FileService
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public static function local($filename, $content)
|
public static function local($filename, $content, $append = false)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$realfile = env('root_path') . $filename;
|
$realfile = env('root_path') . $filename;
|
||||||
!file_exists(dirname($realfile)) && mkdir(dirname($realfile), 0755, true);
|
!file_exists(dirname($realfile)) && mkdir(dirname($realfile), 0755, true);
|
||||||
if (file_put_contents($realfile, $content, FILE_APPEND)) {
|
if (file_put_contents($realfile, $content, $append ? FILE_APPEND : 0)) {
|
||||||
$url = pathinfo(request()->baseFile(true), PATHINFO_DIRNAME) . '/' . $filename;
|
$url = pathinfo(request()->baseFile(true), PATHINFO_DIRNAME) . '/' . $filename;
|
||||||
return ['file' => $realfile, 'hash' => md5_file($realfile), 'key' => "{$filename}", 'url' => $url];
|
return ['file' => $realfile, 'hash' => md5_file($realfile), 'key' => "{$filename}", 'url' => $url];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user