fakeface
fakeface copied to clipboard
SSL certificate problem: certificate has expired
Hi: I have this code to get and save face image from your API:
[request.php]
$minAge = 18;
$maxAge = 81;
$gender = 'male';
$fakeFaceUrl = "https://fakeface.rest/face/json?minimum_age={$minAge}&maximum_age={$maxAge}&gender={$gender}";
$obj = json_decode(file_get_contents($fakeFaceUrl), true);
$imageBaseName = 11 . '-img-profile-';
$response = fetchImageFromUrl($obj['image_url'], 'imags/uploads/users', false, $imageBaseName);
[helper.php]
if(!function_exists('fetchImageFromUrl')) {
function fetchImageFromUrl(
string $url,
?string $dir,
bool $isFullPath,
?string $imageBaseName
): bool|\RuntimeException|string {
$dir = $dir === null ? sys_get_temp_dir() : $dir; // GNU/Linux / OS X / Windows compatible
// Validate directory path
if (! is_dir($dir) || ! is_writable($dir)) {
mkdir($dir, 0777, true);
}
$imageBaseName = $imageBaseName === null ? '' : $imageBaseName;
$parts = explode('.', $url);
$imageExtension = end($parts);
// Generate a random filename. Use the server address so that a file
// generated at the same time on a different server won't have a collision.
$name = md5(uniqid(empty($_SERVER['SERVER_ADDR']) ? '' : $_SERVER['SERVER_ADDR'], true));
$filename = $imageBaseName . $name . "." . $imageExtension;
$filepath = $dir . DIRECTORY_SEPARATOR . $filename;
// save file
if (function_exists('curl_exec')) {
// use cURL
$fp = fopen($filepath, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0');
// - Para no exigir VALIDEZ DE CERTICADO SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;
fclose($fp);
curl_close($ch);
if (! $success) {
unlink($filepath);
echo "\nNO_SUCCESS_CURL";
echo "\n";
echo curl_error($ch);
// could not contact the distant URL or HTTP error - fail silently.
return false;
}
} elseif (ini_get('allow_url_fopen')) {
// use remote fopen() via copy()
$success = copy($url, $filepath);
if (! $success) {
// could not contact the distant URL or HTTP error - fail silently.
return false;
}
} else {
return new \RuntimeException('The image formatter downloads an image from a remote HTTP server. Therefore, it requires that PHP can request remote hosts, either via cURL or fopen()');
}
return $isFullPath ? $filepath : $filename;
}
}
When I execute the request, the file doesn't save if the CURL option is applied. Because of this exception or error:
SSL certificate problem: certificate has expired
Only, when I put this line before the curl_exec, everything works fine and the image is saved:
//...
// - To NOT require SSL certificate validation
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;
//...
So, is it possible that your certificate has expired and needs to be renewed, or could the source of the error be something else? Thanks for any response. Regards
Should be fixed now, please check
Should be fixed now, please check
No, I just try and get the same error.