...
|
|
@ -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" => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
14
MyObsidianVault/Knowledgebase/PHP/set unique name.md
Normal 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);
|
||||||
|
```
|
||||||
|
|
@ -26,5 +26,7 @@ Creates Controller, Model, Migration, Seeder
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
php spark migrate:status
|
||||||
|
|
||||||
php spark migrate
|
php spark migrate
|
||||||
```
|
```
|
||||||
|
|
@ -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]]
|
||||||
|
|
@ -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]]
|
||||||
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
Routes.php
|
||||||
|
![[Pasted image 20241117113037.png]]
|
||||||
|
|
||||||
|
Route parameter
|
||||||
|
![[Pasted image 20241117113342.png]]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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" => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
BIN
MyObsidianVault/_images/Pasted image 20241116111944.png
Normal file
|
After Width: | Height: | Size: 252 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241116113439.png
Normal file
|
After Width: | Height: | Size: 183 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241116113532.png
Normal file
|
After Width: | Height: | Size: 224 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241117112106.png
Normal file
|
After Width: | Height: | Size: 188 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241117113037.png
Normal file
|
After Width: | Height: | Size: 266 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241117113342.png
Normal file
|
After Width: | Height: | Size: 299 KiB |
BIN
MyObsidianVault/_images/Pasted image 20241117113802.png
Normal file
|
After Width: | Height: | Size: 270 KiB |