Jump to content

curl image into mysql.


zz50

Recommended Posts

hi, i got a problem insert a image that downloaded into mysql database, because when i echo $sqlCmd, it output $data in binary file, please help

thanks

 

<?php

require ('dbconf.inc.php');

$table="myTable";

makeConnection($dbHost, $dbUser, $dbPasswd);

 

$url = 'http://www.google.com/intl/en_ALL/images/logo.gif';

$curl_handler = curl_init();

curl_setopt($curl_handler, CURLOPT_URL, $url);

curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_handler, CURLOPT_BINARYTRANSFER, 1); //return the transfer in a binary format .

$data = curl_exec($curl_handler);

curl_close($curl_handler);

 

 

$sqlCmd ="INSERT INTO $table(pid,city,cat,title,info,img1) values('10','mycity','apa','me','yo',$data)";

mysql_query("$sqlCmd", $link) or die(mysql_errno() . ": " . mysql_error() . "<br>");

 

?>

Link to comment
https://forums.phpfreaks.com/topic/97414-curl-image-into-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.