Other similar posts did not fix this error.
Using Codeigniter and Openai API to generate images.
Started getting this error after server migration.
Now it just places 0 byte img file on the server and throws this error.
It was 3MB images before, not huge.
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(https://oaidalleapiprodscus.blob.core.windows.net/private/org-vsNFQNxeX6XH5mkcucSgjmwr/user-xrjvRzlnKwWRfjibOKWJRpd6/img-3VQ4qjdmWfizq6mWRGRl7TgI.png?st=2024-09-28T13%3A24%3A34Z&se=2024-09-28T15%3A24%3A34Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2024-09-28T00%3A48%3A37Z&ske=2024-09-29T00%3A48%3A37Z&sks=b&skv=2024-08-04&sig=6zC7Ix2wBA3L1Bn9OYW%2BeE%2BX5svP0AsRjm%2BTe%2BbobNo%3D): failed to open stream: no suitable wrapper could be found
Filename: controllers/Images.php
Line Number: 599
Backtrace:
File: /home/rztxdnnj/public_html/app/application/controllers/Images.php
Line: 599
Function: file_get_contents
File: /home/rztxdnnj/public_html/app/index.php
Line: 316
Function: require_once
Tryd the image link, its working
allow_url_fopen and file_get_contents are On
Images.php:
public function ai_image_generator(){
$keys_words = '';
if(isset($_POST['key_words'])):
$keys_words = html_escape($_POST['key_words']);
endif;
$image_size = '';
if(isset($_POST['image_size'])):
$image_size = html_escape($_POST['image_size']);
endif;
$ogj = str_replace(" ","%20",$keys_words);
if(!empty($image_size)){
$size = $image_size;
}else{
$size = "1024x1024";
}
if(!empty($ogj)){
$args = array(
"prompt" => $ogj,
"n"=>1,
"size"=>$size,
'model' => 'dall-e-3'
);
$data_string = json_encode($args);
$ch = curl_init('https://api.openai.com/v1/images/generations');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.AI_IMAGES_CODE
'Content-Type: application/json'
));
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$a = json_decode($result,true);
if(isset($a['data'])){
foreach($a['data'] as $a_child){
$image_path = 'openai_images'.rand(10,100);
$img = 'uploads/ai/'.$image_path.'.png';
$imgUrl = $a_child['url'];
file_put_contents($img, file_get_contents($imgUrl));
$img_url= base_url().'/uploads/ai/'.$image_path.'.png';
echo '<div data-url="'.$img_url.'"><img src="'.$img_url.'" alt="AI IMAGES"></div>';
}
}else{
echo '<p>'.esc_html($a['error']['message']).'</p>';
}
}else{
echo '<p>'.esc_html__('Please Enter Object Name.','gpt-blaster').'</p>';
}
die();
}
I donot own the server, i am not sure what they did or did nothing at all to solve this. But what am sure off that allow_url_fopen and file_get_contents are On.