<!DOCTYPE html>
<html>
<head>
<title>Project APi File Convert</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form action="curl.php" method="POST" enctype="multipart/form-data">
<div class="container">
</br></br></br></br></br></br>
<div class="form-group">
<label>Select Input Format</label>
<select class="form-control" name="inputformat">
<option>Select Format</option>
<option value="key">key</option>
<option value="pages">pages</option>
<option value="numbers">numbers</option>
<option value="docx">docx</option>
<option value="png">png</option>
<option value="jpg">jpg</option>
<!-- <option value="pdf">PDF</option> -->
</select>
</div>
<div class="form-group">
<label >Select Output Format</label>
<select class="form-control" name="outputformat">
<option>Select format</option>
<!-- <option value="png">PNG</option>
<option value="jpg">JPG</option>
<option value="docx">DOCX</option> -->
<option value="pdf">PDF</option>
</select>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>File input</label>
<input type="file" class="form-control-file" name="image">
</div>
</div>
</div>
<input type="submit" value="upload" name="s" class="btn btn-primary">
</div>
</form>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" ></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" ></script>
Curl.php
===========================
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['s']))
{
$inputExt=$_POST['inputformat'];
$outputExt=$_POST['outputformat'];
{
$filename=$_FILES['image']['name'];
$tmp_name =$_FILES['image']['tmp_name'];
$str="8fdfds3fdds7fdg83ufhfjd3rhffjfh838";
$str=str_shuffle($str);
$str=substr($str,0,4);
$new_name=$str.'-'.$filename;
$destination="upload/".$new_name;
$res=move_uploaded_file($tmp_name,$destination);
$path='http://practice.arbutus.online/pradeep/success/upload/'.$new_name;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL =>'https://api.cloudconvert.com/v1/convert',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST =>'POST',
CURLOPT_POSTFIELDS => json_encode(array(
'apikey' => 'xxxxxx-your-api-key-xxxx',
'inputformat' =>$inputExt,
'outputformat' =>$outputExt,
'input' =>'download',
'file'=>$path,
'converteroptions' => array(
'density' => '24'
),
/*'output' => array(
's3' => array(
'accesskeyid' => 'xxxxxx',
'bucket' => 'xxxxxx',
'secretaccesskey' => 'xxxxxxxx',
'region' => 'xxxxx',
'acl' => 'public-read',
'path' => '/storage/content'.'/'
)
),*/
'download' =>true,
'wait' => false,
'save' => false
)),
CURLOPT_HTTPHEADER => array(
'cache-control: no-cache',
'content-type: application/json'
),
));
$response = curl_exec($curl);
$response = str_replace('See Other. Redirecting to ', '', $response);
$err = curl_error($curl);
curl_close($curl);
$data = json_decode(file_get_contents($response), true);
//print_r($data);
$result = $data["output"]["url"];
$result="https:$result";
// var_dump("$result");
// header("Location:/$result"); exit();
echo '<script>window.location ="'.$result.'";</script>';
}
}
?>
Comments
Post a Comment