Skip to content

Commit 0fa6cc4

Browse files
committed
fix upload file and folder name in windows
1 parent 42fadb2 commit 0fa6cc4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/traits/LfmHelpers.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public function getCurrentPath($file_name = null, $is_thumb = null)
1919
{
2020
$path = $this->composeSegments('dir', $is_thumb) . $file_name;
2121

22+
if ($this->isRunningOnWindows()) {
23+
$path = str_replace('/', '\\', $path);
24+
}
25+
2226
return base_path($path);
2327
}
2428

@@ -172,13 +176,16 @@ public function getUserSlug()
172176

173177
public function getFileName($file)
174178
{
179+
if ($this->isRunningOnWindows()) {
180+
$file = str_replace('\\', '/', $file);
181+
}
175182
$lfm_dir_start = strpos($file, $this->getPathPrefix('dir'));
176183
$working_dir_start = $lfm_dir_start + strlen($this->getPathPrefix('dir'));
177184
$lfm_file_path = substr($file, $working_dir_start);
178185

179186
$arr_dir = explode('/', $lfm_file_path);
180187
$arr_filename['short'] = end($arr_dir);
181-
$arr_filename['long'] = '/' . $lfm_file_path;
188+
$arr_filename['long'] = str_replace('//', '/', '/' . $lfm_file_path);
182189

183190
return $arr_filename;
184191
}
@@ -194,4 +201,9 @@ public function humanFilesize($bytes, $decimals = 2)
194201
$factor = floor((strlen($bytes) - 1) / 3);
195202
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
196203
}
204+
205+
public function isRunningOnWindows()
206+
{
207+
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
208+
}
197209
}

0 commit comments

Comments
 (0)