Skip to content

Commit

Permalink
fix: image field name
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Sep 22, 2023
1 parent 6e9fe1b commit 701b42b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function showImagesPage(Request $request): View
public function uploadPostImage(Request $request): RedirectResponse
{
$request->validate([
'upload_image' => 'required|image|mimes:jpeg,jpg,png|max:2048',
'image' => 'required|image|mimes:jpeg,jpg,png|max:2048',
]);

$file = $request->file('upload_image');
$file = $request->file('image');
$filename = ImageController::sanatizeImageFilename($file);

ImageManagerStatic::make($file)
Expand Down Expand Up @@ -89,8 +89,8 @@ public function deletePostImage(Request $request, int $id): RedirectResponse
*/
public static function sanatizeImageFilename($file): string
{
$filename = preg_replace('/[^A-Za-z0-9\-\_]/', '', pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
$fileExtension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
$filename = preg_replace('/[^A-Za-z0-9\-\_]/', '', $file->getClientOriginalName());
$fileExtension = $file->getClientOriginalExtension();
$newFilename = $filename . '-' . time() . '.' . $fileExtension;

return $newFilename;
Expand Down
4 changes: 2 additions & 2 deletions src/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function updatePassword(Request $request): RedirectResponse
public function updateProfilePic(Request $request): RedirectResponse
{
$request->validate([
'upload_profile_pic' => 'required|image|mimes:jpeg,jpg,png|max:2048',
'image' => 'required|image|mimes:jpeg,jpg,png|max:2048',
]);
$file = $request->file('upload_profile_pic');
$file = $request->file('image');
$filename = ImageController::sanatizeImageFilename($file);

ImageManagerStatic::make($file)
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/images.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<label>Upload an Image</label>
<small class="avatar-upload-criteria">Picture must be a jpg or png no bigger than 2mb.</small>
<label for="image" class="btn btn-primary">Upload Image</label>
<input type="file" name="upload_image" id="image" onchange="this.form.submit()" hidden>
<input type="file" name="image" id="image" onchange="this.form.submit()" hidden>
</form>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class="avatar">
@endif
<br />
<label for="profile_pic" class="btn btn-primary">Update Profile Picture</label>
<input type="file" name="upload_profile_pic" id="profile_pic" onchange="this.form.submit()" hidden>
<input type="file" name="image" id="profile_pic" onchange="this.form.submit()" hidden>
</form>

</div>
Expand Down

0 comments on commit 701b42b

Please sign in to comment.