fixing
This commit is contained in:
parent
901e1aca33
commit
457b8f3da8
|
|
@ -126,29 +126,10 @@ public function upload(Request $request, $project_id)
|
||||||
{
|
{
|
||||||
if ($request->hasFile('folder_path')) {
|
if ($request->hasFile('folder_path')) {
|
||||||
$project_title = Project::find($project_id)->title;
|
$project_title = Project::find($project_id)->title;
|
||||||
$project_title = str_replace([' ', '/', '\\'], '-', $project_title);
|
|
||||||
|
|
||||||
$file = $request->file('folder_path');
|
$file = $request->file('folder_path');
|
||||||
$file_name = $file->getClientOriginalName();
|
$file_name = $file->getClientOriginalName();
|
||||||
$folder_path = 'public/tmp/submissions/' . $request->user()->id . '/' . $project_title;
|
$folder_path = 'public/tmp/submissions/' . $request->user()->id . '/' . $project_title;
|
||||||
|
|
||||||
// Hapus temporary file lama jika ada
|
|
||||||
TemporaryFile::where('folder_path', $folder_path)->delete();
|
|
||||||
|
|
||||||
// Hapus folder lama jika ada
|
|
||||||
$full_folder_path = storage_path('app/' . $folder_path);
|
|
||||||
if (is_dir($full_folder_path)) {
|
|
||||||
// Hapus semua file di folder
|
|
||||||
$files = glob($full_folder_path . '/*');
|
|
||||||
foreach($files as $file_to_delete) {
|
|
||||||
if(is_file($file_to_delete)) {
|
|
||||||
unlink($file_to_delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rmdir($full_folder_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload file baru
|
|
||||||
$file->storeAs($folder_path, $file_name);
|
$file->storeAs($folder_path, $file_name);
|
||||||
|
|
||||||
TemporaryFile::create([
|
TemporaryFile::create([
|
||||||
|
|
@ -772,12 +753,6 @@ public function update(Request $request)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete temp directory if is not empty
|
|
||||||
$tempDir = $this->getTempDir($submission);
|
|
||||||
if (!$this->is_dir_empty($tempDir)) {
|
|
||||||
Process::fromShellCommandline('rm -rf ' . $tempDir)->run();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->has('folder_path')) {
|
if ($request->has('folder_path')) {
|
||||||
$submission->type = Submission::$FILE;
|
$submission->type = Submission::$FILE;
|
||||||
$submission->path = $request->folder_path;
|
$submission->path = $request->folder_path;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user