An example of a multiport / data shape in fine microstructure

I am developing apis for android and ios application in fine framework. I recently ran into a problem where I need to upload videos or images using multipart / form-data.

Can anyone provide me with an example of this in fine microstructure?

+3


source to share


1 answer


Here's my simple example:

HTML form

<form enctype="multipart/form-data" action="/uploadPhoto" method="POST">
    Select photo: <input name="photo" type="file" />
    <input type="submit" value="Upload" />
</form>

      



PHP:

$app->post('/uploadPhoto', function () use ($app) {

    $uploadDir = '/full/path/to/upload/dir/';
    $error = false;

    if (empty($_FILES)) {
        echo 'No files';
        $app->stop();
    }

    if (!empty($_FILES['photo']) && $_FILES['photo']['error'] !== 4) {
        if (!$_FILES['photo']['error']) {
            if (!move_uploaded_file($_FILES['photo']['tmp_name'], $uploadDir.$_FILES['photo']['name'])) {
                echo 'There is a error while processing uploaded file';
                $app->stop();
            }
        } else {
            echo 'Error while uploading file';
            $app->stop();
        }
    }

    echo 'Success!';
});

      

0


source







All Articles