|
@@ -37,13 +37,12 @@ class FileService
|
|
|
* @return File
|
|
* @return File
|
|
|
* @throws Exception
|
|
* @throws Exception
|
|
|
*/
|
|
*/
|
|
|
- public function createZipArchive(string $path, string $archiveName, int $userId = null, bool $deleteSourceFiles = false): File
|
|
|
|
|
|
|
+ public function createZipArchive(string $path, string $archiveName, int $userId = null): File
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
if (!($tempFile = tempnam(sys_get_temp_dir(), Str::random()))) {
|
|
if (!($tempFile = tempnam(sys_get_temp_dir(), Str::random()))) {
|
|
|
throw new Exception('Cant create temporary file!');
|
|
throw new Exception('Cant create temporary file!');
|
|
|
}
|
|
}
|
|
|
- var_dump(storage_path('app/public/' . $path));
|
|
|
|
|
|
|
|
|
|
$zip = new ZipArchive();
|
|
$zip = new ZipArchive();
|
|
|
$fullPath = storage_path('app/public/' . $path);
|
|
$fullPath = storage_path('app/public/' . $path);
|
|
@@ -56,20 +55,16 @@ class FileService
|
|
|
if(!$file->isDir()) {
|
|
if(!$file->isDir()) {
|
|
|
// Get real and relative path for current file
|
|
// Get real and relative path for current file
|
|
|
$filePath = $file->getRealPath();
|
|
$filePath = $file->getRealPath();
|
|
|
- var_dump($filePath);
|
|
|
|
|
$relativePath = substr($filePath, strlen($fullPath) + 1);
|
|
$relativePath = substr($filePath, strlen($fullPath) + 1);
|
|
|
- var_dump($relativePath);
|
|
|
|
|
// Add current file to archive
|
|
// Add current file to archive
|
|
|
$zip->addFile($filePath, $relativePath);
|
|
$zip->addFile($filePath, $relativePath);
|
|
|
- if($deleteSourceFiles) {
|
|
|
|
|
- Storage::disk($file->disk)->delete($file->path);
|
|
|
|
|
- $file->delete();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
$zip->close();
|
|
$zip->close();
|
|
|
|
|
+
|
|
|
$fileModel = File::query()->updateOrCreate([
|
|
$fileModel = File::query()->updateOrCreate([
|
|
|
- 'link' => url('/storage/') . '/' . $path . '/' .$archiveName,
|
|
|
|
|
|
|
+ 'link' => url('/storage/') . '/' . Str::replace('/tmp', '', $path) . '/' .$archiveName,
|
|
|
'path' => $path . '/' .$archiveName,
|
|
'path' => $path . '/' .$archiveName,
|
|
|
'user_id' => $userId ?? auth()->user()->id,
|
|
'user_id' => $userId ?? auth()->user()->id,
|
|
|
'original_name' => $archiveName,
|
|
'original_name' => $archiveName,
|