This commit is contained in:
Torsten 2024-11-17 12:05:52 +01:00
parent cedf373c03
commit e225e05c52
21 changed files with 121 additions and 0 deletions

View file

@ -0,0 +1,23 @@
```php
$imageFile = $this->request->getFile("profile_image");
$imageName = $imageFile->getName();
$tempArray = explode(".", $imageName);
$newImageName = round(microtime(true)) . "" . end($tempArray);
if($imageFile->move("images/" . $newImageName)) { // move automatically creates images folder if not exists
$response = [
"status" => false,
"message" => "Image successfully uploaded",
"data" => []
];
} else {
$response = [
"status" => false,
"message" => "Image Upload failed",
"data" => []
];
}
```

View file

@ -0,0 +1,14 @@
```php
$uniqueName = round(microtime(true))
```
Application for storing unique Image Name
```php
$tempArray = explode(".", $imageName);
$newImageName = round(microtime(true)) . "" . end($tempArray);
```

View file

@ -26,5 +26,7 @@ Creates Controller, Model, Migration, Seeder
```bash
php spark migrate:status
php spark migrate
```

View file

@ -0,0 +1,12 @@
https://www.youtube.com/watch?v=rlIKHZ5Nq2U&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=14
app/Filters
app/Config/Filters.php
![[Pasted image 20241116111944.png]]
```bash
php spark make:filter Auth --suffix
```
![[Pasted image 20241116113439.png]]
![[Pasted image 20241116113532.png]]

View file

@ -0,0 +1,11 @@
```bash
php spark make:controller Api/Api --suffix --restful
```
#17/38
== > Created controller ApiController (in Controlles subfolder Api) will have 9 methods.
( WHich the tutorial doesnt use, basically only difference to standard Controllers is usage of ResourceController)
![[Pasted image 20241117112106.png]]

View file

@ -0,0 +1,8 @@
Routes.php
![[Pasted image 20241117113037.png]]
Route parameter
![[Pasted image 20241117113342.png]]

View file

@ -0,0 +1,51 @@
![[Pasted image 20241117113802.png]]
```php
$studentObject = new StudentModel();
$imageFile = $this->request->getFile("profile_image");
// only go through image storing logic if image actually exists in payload
if (isset($imageFile) && !empty($imageFile)) { // with image
$imageName = $imageFile->getName();
$tempArray = explode(".", $imageName);
$newImageName = round(microtime(true)) . "" . end($tempArray);
if($imageFile->move("images/" . $newImageName)) { // move automatically creates images folder if not exists
$data = [
"name" => $this->request->getVar("name"),
"email" => $this->request->getVar("email"),
"profile_image" => "images/" . $newImageName
];
}
else {
$response = [
"status" => false,
"message" => "Image Upload failed",
"data" => []
];
}
}
else { // without image
$data = [
"name" => $this->request->getVar("name"),
"email" => $this->request->getVar("email"),
];
}
// store student
if ($studentObject->insert($data)) {
$response = [
"status" => true,
"message" => "Student saved successfully",
"data" => []
];
} else {
$response = [
"status" => false,
"message" => "Failed to save student",
"data" => []
];
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 KiB