0

I need to save an image from an input with js to mysql

I use php but it doesn't work for me, the content of the variable disappears when it goes through the duPost method

My input

<div class="mb-3 custom-file">
       <label for="formFile" class="custom-file-input">Imagen de Entrada</label>
       <input class="form-control" type="file" id="formFile" name="imgFile">
</div>

where does the information go

$idCabin = $_POST['s']; 
$nameCabin = $_POST['nombreCabana'];
$desCabin = $_POST['desCabana'];
if (isset($_FILES['imgFile']['name'])){
    $tamanoArchivo = $_FILES['imgFile']['size'];
    $imagenSubida = fopen($_FILES['imgFile']['tmp_name'], 'r');
    $binariosImagen= fread($imagenSubida, $tamanoArchivo);
}
$url = 'store/saveCabinPost';

$data = new stdClass();
$data->idStore = $idCabin;
$data->nameStore = $nameCabin;
$data->storeDescription = $desCabin;
$data->storeImage = $binariosImagen;

$response = doPost($url, $data);

and where it collects the information from the database

public function saveCabinPostAction()
{
    $responseData = new ResponseData();
    $responseJson;
    $arrQueryStringParams = $this->getQueryStringParams();

    try {
        $StoreModel = new StoreModel();
        $inputJSON = file_get_contents('php://input'); //extraer datos del cuerpo del request
        $input = json_decode($inputJSON); //convert JSON into array


        //a partir de aqui
        $idStore = $input->idStore;
        $nameStore = $input->nameStore;
        $storeDescription = $input->storeDescription;
        $storeImage = $input->storeImage;
        
        //$arrID = $userModel->ultimoRegistroCabin();

        //$responseData->messageError = $userModel->ultimoRegistroCabin();
        //$responseData->data = $arrID[0];

        //seleccionamos el usuario desde BD
        $arrUsers = $StoreModel->saveCabin($idStore, $nameStore, $storeDescription, $storeImage);
        $responseData->success = true;

    } catch (Error $e) {

        $responseData->success = false;
        $responseData->messageError =  $e->getMessage();
    }

    $responseJson = json_encode($responseData);
    $this->sendOutput(
        $responseJson,
        array('Content-Type: application/json', 'HTTP/1.1 200 OK')
    );
}

0 Answers0