The base64-encode was a last ditch effort in an attempt to find a working solution to my problem. It didn't help. Here is some of the code that I'm using in an attempt to achieve my goal. This function just retreives the image from the inputted url. Clearly, when I'm using this I have a valid image url.
$img = FetchImage("http://example.com/no/image/here.jpg");
function FetchImage($url)
{
$fetch = curl_init();
curl_setopt($fetch, CURLOPT_URL, $url);
curl_setopt($fetch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($fetch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($fetch, CURLOPT_FORBID_REUSE, true);
curl_setopt($fetch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($fetch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($fetch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($fetch);
curl_close($fetch);
return base64_encode($data);
}
After this function is called the binary image data is inserted into my database as a blob (which I know is getting inserted correctly as I'm using prepared statements and using send_long_data for the image).
I have tested echoing out the binary image data right after downloading it and the image showed up perfectly, but once it was inserted into the database it became blurry and fragmented (top half or bottom half is just missing).
Here is my mysql insert query:
if($query = $database->connection->prepare("INSERT INTO media (hidden, hidden, hidden, hidden, hidden, hidden, hidden, image, hidden) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"))
{
$query->bind_param("sbssssbbs", $hidden, $hidden, $hidden, $hidden, $hidden, $hidden,$hidden, $tmp['image'], $hidden);
$query->send_long_data(7, $tmp['image']);
$query->execute();
$result = $query->affected_rows;
if(isset($query->error))
printf("Error Message: %s<br>", $query->error);
$query->close();
}
Suggestions?