<html> <body> <?php require_once '../process.php'; try { $p = new ConvertBook(); $p->convertFromUrl("http://google.com"); print "OK"; } catch (Exception $e) { print $e->getCode() . " - " . $e->getMessage(); } ?> </body> </html>
require_once 'process.php'; require_once 'utils.php'; $url = isset($_GET["url"]) ? $_GET["url"] : null; $email = isset($_POST["email"]) ? $_POST["email"] : null; if (isset($_POST["format"])) { $format = $_POST["format"]; } if (!$format || $format == '') { $format = 1; } $conv = new ConvertBook(); $file = null; try { if ($url || $_POST['uploadtype'] == 'url') { $file = $url ? $url : $_POST['url']; $conv->convertFromUrl($file, $format, $email); } else { if ($_POST['uploadtype'] == 'file') { $err_upload = $_FILES['fileupload']['error']; if ($err_upload == UPLOAD_ERR_OK) { // check uploaded file $path = $_FILES['fileupload']['tmp_name']; $file = $_FILES['fileupload']['name']; $conv->convertFromFile($path, $file, $format, $email); } else { // deal with errors if ($err_upload == UPLOAD_ERR_INI_SIZE || $err_upload == UPLOAD_ERR_FORM_SIZE) { throw new Exception("The uploaded file exceeds the maximum allowed size.", ConvertBook::ERR_SIZE); } else { throw new Exception("Unable to upload file. PHP error - " . $err_upload, ConvertBook::ERR_LOAD); }
<?php require_once 'process.php'; require_once 'utils.php'; if (!isset($_GET["url"])) { httpResponseCode("400 Bad Request", "Missing paremeter \"url\""); die; } try { $conv = new ConvertBook(); $conv->convertFromUrl($_GET["url"], $_GET["format"]); $key = $conv->bookKey; $author = $conv->book->author; $title = $conv->book->title; // generate response header('HTTP/1.0 200 OK'); header('Content-type: application/json'); $response = "{\n 'key' : '{$key}',\n 'author': '{$author}',\n 'title' : '{$title}'\n }"; echo $response; } catch (Exception $e) { $errCode = null; if ($e->getCode() == ConvertBook::ERR_ILLEGAL_ARG) { $errCode = "400 Bad Request"; } else { if ($e->getCode() == ConvertBook::ERR_LOAD) { $errCode = "400 Bad Request"; } else { if ($e->getCode() == ConvertBook::ERR_FORMAT) { $errCode = "404 Not Found"; } else { if ($e->getCode() == ConvertBook::ERR_CONVERT) {