Example of PHP HTTP POST link with Upload web service

Modified on Fri, 24 Dec 2021 at 10:31 AM

Below you will find an example of an application that allows you to submit documents in Yuki by using PHP via the Upload web service.


Example


<html>
<body>

        <form enctype="multipart/form-data" method="POST">

                <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />

                <table>

                        <tr>

                                <td>WebserviceAccessKey</td>

                                <td><input style="width: 250px" id="webserviceaccesskey" name="webserviceaccesskey"></td>

                        </tr>

                        <tr>

                                <td>Administratie ID</td>

                                <td><input style="width: 250px" id="administrationid" name="administrationid"></td>

                        </tr>

                        <tr>

                                <td>Te verzenden bestand:</td>

                                <td><input name="fileupload1" type="file" />

                                </td>

                        </tr>

                        <tr>

                                <td colspan="2"><input type="submit" value="verzenden" /></td>

                        </tr>

                </table>

        </form>
</body>
</html>
<?php
try {

            $filename = $_FILES['fileupload1']['name'];

            $filesize = $_FILES['fileupload1']['size'];

            $filedata = file_get_contents($_FILES['fileupload1']['tmp_name']);

            if($filesize > 0) {

                    $webservice_url = 'https://api.yukiworks.nl/docs/Upload.aspx';


                    $key = $_REQUEST['webserviceaccesskey'];

                    $admin_id = $_REQUEST['administrationid'];


                    $url = $webservice_url . '?WebServiceAccessKey=' . $key . '&Administration=' . $admin_id . '&FileName=' . urlencode($filename);


                    $params = array('http' => array(

                        'method' => 'POST',
                        'header' => 'Content-Length: ' . $filesize,

                        'content' => $filedata

                    )); 


            $ctx = stream_context_create($params);

            $fp = fopen($url, 'rb', false, $ctx);


            $response = @stream_get_contents($fp);


            print_r($response);

    }
}
catch(Exception $e) {

    print $e;
}
?>


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article