rapid-porn

חינם
על ידי yourComputerGuy | מְעוּדכָּן vor 3 Monaten | Entertainment
פּוֹפּוּלָרִיוּת

9.5 / 10

חֶבִיוֹן

749ms

רמת שירות

93%

Health Check

N/A

חזרה לכל הדיונים

in what format the image came from API, i cant render it

Rapid account: Eugene Veprytskyi
eugene.veprytskyi
vor 8 Monaten

issue

Rapid account: Jeankassiocheib 3
jeankassiocheib3 Commented vor einem Monat

If you using PHP:

$images = new Images;

	$file = dirname(__FILE__) . "/media/media.jpg";
	
	$image = $images->getImage($term);
	
	if($image !== false){
		file_put_contents($file, $image);
	}

/*
Class with functions
*/
class Images{
private function isNotJson(string){ json_decode(string);
return json_last_error() !== JSON_ERROR_NONE;
}

public function getImage($term){
	
	$curl = curl_init();

	curl_setopt_array($curl, [
		CURLOPT_URL => "https://rapid-porn.p.rapidapi.com/photo?category=". $term,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "GET",
		CURLOPT_HTTPHEADER => [
			"X-RapidAPI-Host: rapid-porn.p.rapidapi.com",
			"X-RapidAPI-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		],
	]);

	$response = curl_exec($curl);
	$err = curl_error($curl);

	curl_close($curl);

	if($err){
		return false;
	}else{
		
		if($this->isNotJson($response)){
			return $response;
		}else{
			return false;
		}
		
	}
	
}

}

הצטרף לדיון - הוסף תגובה למטה:

התחבר / הירשם כדי לפרסם תגובות חדשות