public function actionUploadFile() { require_once Yii::app()->basepath . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'crocodoc' . DIRECTORY_SEPARATOR . 'crocodoc.php'; $filename = $_FILES["file"]["name"]; $filepath = Yii::app()->basepath . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . Yii::app()->user->id . "_" . $filename; $ext = substr($filename, strpos($filename, '.') + 1, strlen($filename) - 1); $title = substr($filename, 0, strpos($filename, '.')); if ($ext === "txt" || $ext === "docx" || $ext === 'doc' || $ext === 'pdf') { $memberresume = new Memberresume(); if ($_FILES["file"]["size"] > 60000000) { throw new CHttpException(0, "File size should be less than 6MB"); } if ($_FILES["file"]["error"] > 0) { throw new CHttpException('', "Error uploading file. Please try again."); } else { move_uploaded_file($_FILES["file"]["tmp_name"], $filepath); $mrid = $memberresume->saveFileData($title, $filepath); } if ($mrid > 0) { //$uploadedfile = Yii::app()->getAssetManager()->publish($targetpath); //$filepath = Yii::app()->getAssetManager()->getPublishedPath($uploadedfile); //$filepath = 'C:\Users\rgummadi\Dropbox\WWW\myresumeat\assets\557cba7b\104_GummadiDBAResume.doc'; if ($_SERVER['SERVER_NAME'] == "localhost") { $sitepath = "http://localhost"; } else { $sitepath = "http://myresume.at"; } //$fileurl= $sitepath.$uploadedfile; //$fileurl = "http://www.myresume.at/assets/557cba7b/104_GummadiDBAResume.doc"; // Curl Post // //echo $filepath; $crocodoc = new Crocodoc(); $curlresponse = $crocodoc->uploadFile($filepath); // $url = "https://crocodoc.com/api/v2/document/upload -F token=eZpqgYtA1XTo6wzV7HD2mOCR -F file=@".$filename; $json = json_decode($curlresponse); if (!empty($json)) { //print($json->uuid); $memberresume->updateCrocouuid($mrid, $json->uuid); } $this->redirect(array('member/manage')); } } else { throw new CHttpException('', "Only word,pdf,text documents can be uploaded"); } }
<?php /** * Bootstrap */ error_reporting(E_ALL); $exampleApiToken = 'YOUR_API_TOKEN'; // set the content type to plaintext if we're running this from a web browser if (php_sapi_name() != 'cli') { header('Content-Type: text/plain'); } require_once 'Crocodoc.php'; Crocodoc::setApiToken($exampleApiToken); /* * Example #1 * * Upload a file to Crocodoc. We're uploading Form W4 from the IRS by URL. */ echo 'Example #1 - Upload Form W4 from the IRS by URL.' . "\n"; $formW4Url = 'http://www.irs.gov/pub/irs-pdf/fw4.pdf'; echo ' Uploading... '; $uuid = null; try { $uuid = CrocodocDocument::upload($formW4Url); echo 'success :)' . "\n"; echo ' UUID is ' . $uuid . "\n"; } catch (CrocodocException $e) { echo 'failed :(' . "\n"; echo ' Error Code: ' . $e->errorCode . "\n"; echo ' Error Message: ' . $e->getMessage() . "\n"; }