2017-06-17 140 views
0

我们使用PHP curl将图像保存到数据库。我们从xml中获取图像的地址。录制完图像后,我们遇到以下问题。图像叠加,它们被错误地记录。或者图像以名称保存为空白图像。使用PHP curl获取/保存图像

function resim($link, $klasor, $dosya) 
{ 
    if (!file_exists($klasor)) { 
     mkdir($klasor); 
    } 

    $type = strtolower(substr(strrchr($link,"."),1)); 
    if ($type == 'jpeg') { 
     $type = 'jpg'; 
    } 

    $resim = fopen("{$klasor}/{$dosya}.{$type}", 'w'); 

    $ch = curl_init($link); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_NOPROGRESS, false); 
    curl_setopt($ch, CURLOPT_FILE, $resim); 
    curl_exec($ch); 

    curl_close($ch); 
    fclose($resim); 
} 
  • 我们在哪里犯错?或者我们可以用另一种方式做到吗?
  • 我们如何获得图像完成信息?

我们的尊重。

回答

0

这取决于处理上载功能的API。您可能会将错误的图像格式传递给API。例如它可能会接受图像的base64内容

+0

感谢Alaa Attia Mohamed。我们将对文件格式加以限制。最好的祝福。 –