Last active
March 1, 2016 08:39
-
-
Save vibhavsinha/71d394132a98c049f8aa to your computer and use it in GitHub Desktop.
Upload from your browser in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function send($action, $params, $posts = false){ | |
| $curl = curl_init(); | |
| curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); | |
| curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | |
| $getData = http_build_query($params); | |
| $postData = ['clientSecretKey'=>'CLIENT_SECRET_KEY']; ////Replace the caps CLIENT_SECRET_KEY with your video id. | |
| if ($posts) { | |
| $postData = http_build_query(array_merge($postData, $posts)); | |
| } | |
| curl_setopt($curl, CURLOPT_POST, true); | |
| curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); | |
| $url = "http://api.vdocipher.com/v2/$action/?$getData"; | |
| curl_setopt($curl, CURLOPT_URL,$url); | |
| $html = curl_exec($curl); | |
| curl_close($curl); | |
| return $html; | |
| } | |
| $upload_data = json_decode(send('uploadPolicy', [], ['title'=>'NEW_TITLE']), true); | |
| if (is_null($upload_data)) { | |
| throw new Exception('Exception: ' . $upload_data); | |
| } | |
| ?> | |
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
| </head> | |
| <body> | |
| <form action="<?= $upload_data['upload_link_secure'] ?>" method="post" enctype="multipart/form-data"> | |
| Key to upload: | |
| <input type="hidden" name="key" value="<?= $upload_data['key'] ?>" /><br /> | |
| <input type="hidden" name="success_action_status" value="201" /> | |
| <input type="hidden" name="success_action_redirect" value="https://www.vdocipher.com" /> | |
| <input type="hidden" name="X-Amz-Credential" value="<?= $upload_data['x-amz-credential'] ?>" /> | |
| <input type="hidden" name="X-Amz-Algorithm" value="<?= $upload_data['x-amz-algorithm'] ?>" /> | |
| <input type="hidden" name="X-Amz-Date" value="<?= $upload_data['x-amz-date'] ?>" /> | |
| <input type="hidden" name="Policy" value='<?= $upload_data['policy'] ?>' /> | |
| <input type="hidden" name="X-Amz-Signature" value="<?= $upload_data['x-amz-signature'] ?>" /> | |
| File: | |
| <input type="file" name="file" /> <br /> | |
| <!-- The elements after this will be ignored --> | |
| <input type="submit" name="submit" value="Upload to Amazon S3" /> | |
| </form> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment