Advertisement
hasancse1991

Life card Edit With Multipart File

Sep 3rd, 2021
2,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.     $target_dir = "files/"; //folder name where your files will be stored. create this folder inside "file_upload_api" folder
  3.     $target_file = $target_dir . basename($_FILES["file"]["name"]);
  4.  
  5.  
  6.     $data = '{
  7.     "status": "Success",
  8.     "statusCode": 200,
  9.     "data": {
  10.         "userName": "hellohasan.bs23@gmail.com",
  11.         "firstName": "Hasan",
  12.         "lastName": "Hasan",
  13.         "email": "hellohasan.bs23@gmail.com",
  14.         "birthDate": "1992-08-13T00:00:00+06:00",
  15.         "birthLocation": "",
  16.         "currentLocation": "",
  17.         "mediaUrl": "",
  18.         "quote": "Life is so much beautiful",
  19.         "isDeceased": false,
  20.         "isTemporaryUser": false,
  21.         "id": "4db7e9fd-855f-4388-9746-68d33940ba97",
  22.         "modifiedDate": "2021-09-03T13:00:55.55+06:00",
  23.         "createdDate": "2021-08-25T17:04:54.54+06:00"
  24.    },
  25.     "message": "Successful",
  26.     "errors": null
  27. }';
  28.  
  29.  
  30.     if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)){
  31.         header('Content-Type: application/json');
  32.         $manage = json_decode($data, true);
  33.         echo json_encode($manage);
  34.     } else {
  35.        
  36.     $error = '{
  37.     "status": "Failed",
  38.     "statusCode": 500,
  39.     "data": null,
  40.     "message": "Failed",
  41.     "errors": ["Something went wrong"]
  42.    }';
  43.      header('Content-Type: application/json');
  44.         $manageError = json_decode($error, true);
  45.         echo json_encode($manageError);
  46.     }
  47.        
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement