将图像从url直接上传到数据库blob字段

I am trying to upload an image directly from an url to database blob field.

The only way I managed to do so is by saving the image in my webserver folder and read the file and return the content.

I am looking for a way to transfer the url data content directly to the database blob field.

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$savefile = fopen('objectPic/temp'.$counter.'.jpg', 'w');
fwrite($savefile, $result);
fclose($savefile);
$fp = fopen('objectPic/temp'.$counter.'.jpg', 'r');
$data = fread($fp, filesize('objectPic/temp'.$counter.'.jpg'));
$data = addslashes($data);
fclose($fp);

return $data;

Ok This is the function :

function GetImageFromUrl($link) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_URL, $link);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

this is the code :

$pic1 = GetImageFromUrl($pic1);

db insert

INSERT INTO posts VALUES('', '2', '2', '$objTypeId', '','0', '', '1', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '$pic1', '$pic2', '$pic3')");

tnx alot

try this

 $file = fopen("http://url/img.jpg", "rb");
        $output = fread($file, 10000);
    fclose($file);
    // insert sql code here 
   mysql_query(" INSERT INTO table SET image='$output'");