Skip to main content

cloudconvert to convert file using curl php


<!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

Popular posts from this blog

Insert Fetch Update Delete Mysql data in Codeigniter

Database -- -- Table structure for table `tbl_user` -- CREATE TABLE IF NOT EXISTS `tbl_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `first_name` varchar(200) NOT NULL, `last_name` varchar(200) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=95 ; -- -- Dumping data for table `tbl_user` -- INSERT INTO `tbl_user` (`id`, `first_name`, `last_name`) VALUES (91, 'Harold', 'Jones'), (89, 'Christine', 'Smith'), (88, 'Marker', 'Angela'), (87, 'Romeo', 'Mary'), (86, 'Smith', 'John'); Controller - main.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Main extends CI_Controller { //functions public function index(){ $this->load->model("main_model"); $data["fetch_data"] = $this->main_model->...

How to Generate Excel File in Codeigniter using PHPExcel

Libraries/Excel.php <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once('PHPExcel.php'); class Excel extends PHPExcel { public function __construct() { parent::__construct(); } } ?> Libraries/IOFactory.php <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once('PHPExcel/IOFactory.php'); class IOFactory extends PHPExcel_IOFactory { public function __construct() { parent::__construct(); } } ?> Controllers/Excel_export.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Excel_export extends CI_Controller { function index() { $this->load->model("excel_export_model"); $data["employee_data"] = $this->excel_export_model->fetch_data(); $this->load->view("excel_export_view", $data); } function action() { $this->load->model(...

Core php login logout and register view delete

Core php login logout and register view delete Database.php CREATE TABLE IF NOT EXISTS register.`users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, `password` varchar(50) NOT NULL, `trn_date` datetime NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE IF NOT EXISTS register.`new_record` ( `id` int(11) NOT NULL AUTO_INCREMENT, `trn_date` datetime NOT NULL, `name` varchar(50) NOT NULL, `age`int(11) NOT NULL, `submittedby` varchar(50) NOT NULL, PRIMARY KEY (`id`) ); Auth.php <?php session_start(); if(!isset($_SESSION["username"])){ header("Location: login.php"); exit(); } ?> Dashbaord .php <!DOCTYPE html> <html lang="en"> <head> <title>Dashboard</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.boo...