<?php // phpinfo();die; // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/ // if($_SERVER["REQUEST_METHOD"] == "POST") // { // if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0) // { // $allowed = array("jpg" => "image/jpeg", "png" => "image/png"); // $filename = $_FILES["photo"]["name"]; // $filetype = $_FILES["photo"]["type"]; // $ext = pathinfo($filename, PATHINFO_EXTENSION); // if(array_key_exists($ext, $allowed)) // { $curl = curl_init('https://api.remove.bg/v1.0/removebg'); // curl_setopt($curl, CURLOPT_URL, 'https://api.remove.bg/v1.0/removebg'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // curl_setopt($curl, CURLOPT_CAINFO,__DIR__ . DIRECTORY_SEPARATOR . 'certif.cer'); // curl_setopt($curl, CURLOPT_CAPATH,__DIR__ . DIRECTORY_SEPARATOR); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); $post = array( // 'image_file' => '@' .realpath('/img'.$_FILES["photo"]["name"]), // 'image_url' => 'https://img.buzzfeed.com/buzzfeed-static/static/2019-04/18/5/asset/buzzfeed-prod-web-05/sub-buzz-18749-1555581339-1.jpg', 'image_file' =>realpath('img\pierremarque.jpg'), 'size' => 'auto' ); // $post = http_build_query($post); echo $post['image_file']; echo'<br></br>'; curl_setopt($curl, CURLOPT_POSTFIELDS, $post); $headers = array(); $headers[] = 'X-Api-Key:qYXf5PimffLjeH1i5B1rySQw'; // echo $headers[0]." ".$headers[1];echo'<br></br>'; curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($curl); echo $result; if (curl_errno($curl)) { echo 'Error:' . curl_error($curl); } curl_close($curl); // $fp = fopen($_FILES["photo"]["name"]."no-bg.png", "wb"); $fp = fopen("no-bg.png", "wb"); fwrite($fp, $result); fclose($fp); // } // } // } ?>