Skip to content

Commit

Permalink
Fallback to getPathname() for uploaded files - closes #41054105
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jul 5, 2024
1 parent 78e1067 commit 9b5286e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function mb_ucfirst($string)
// Photo
$validator->after(function ($validator) use ($customer, $request) {
if ($request->hasFile('photo_url')) {
$path_url = $customer->savePhoto($request->file('photo_url')->getRealPath(), $request->file('photo_url')->getMimeType());
$path_url = $customer->savePhoto($request->file('photo_url')->getRealPath() ?: $request->file('photo_url')->getPathname(), $request->file('photo_url')->getMimeType());

if ($path_url) {
$customer->photo_url = $path_url;
Expand Down
2 changes: 1 addition & 1 deletion app/Misc/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ public static function sanitizeUploadedFileName($file_name, $uploaded_file = nul
} elseif ($ext == 'pdf') {
// Rename PDF to avoid running embedded JavaScript.
if ($uploaded_file && !$contents) {
$contents = file_get_contents($uploaded_file->getRealPath());
$contents = file_get_contents($uploaded_file->getRealPath() ?: $uploaded_file->getPathname());
}
if ($contents && strstr($contents, '/JavaScript')) {
$file_name = $file_name.'_';
Expand Down
4 changes: 4 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@ public function savePhoto($uploaded_file, $mime_type = '')
if (!is_string($uploaded_file)) {
$real_path = $uploaded_file->getRealPath();
$mime_type = $uploaded_file->getMimeType();

if (!$real_path) {
$real_path = $uploaded_file->getPathname();
}
}

$photo_size = config('app.user_photo_size');
Expand Down

0 comments on commit 9b5286e

Please sign in to comment.