Jump to content

Insert a remote picture as a blob in mysql from a remote url


sebababi

Recommended Posts

I’ve tried many combinations of these 2 codes

 

This one is to upload to a folder, which is not really what I want.

 

$url = "http://imageurl";

$filename = "filenametosave";

ob_start();

readfile($url);

$img = ob_get_contents();

ob_end_clean();

$size = strlen($img);

$fp = @fopen($filename, "ab");

fwrite($fp,$img);

fclose($fp);

this code is to upload pictures from a form as a BLOB, which is what I want, but instead of uploading from a form I want it from a URL, like $url = "http://imageurl";

 

$fileName = $_FILES['imagefile']['name']; $tmpName  = $_FILES['imagefile']['tmp_name']; $fileSize = $_FILES['imagefile']['size']; $imtype = $_FILES['imagefile']['type']; @list(, , $imtype, ) = getimagesize($_FILES['imagefile']['tmp_name']); // Get image type. if ($imtype == 3) // cheking image type $imageextension="png";  // to use it later in HTTP headers elseif ($imtype == 2) $imageextension="jpeg"; elseif ($imtype == 1) $imageextension="gif"; else $msg = 'Error: unknown file format'; $fp      = fopen($tmpName, 'r+'); $content = fread($fp, filesize($tmpName)); //reads $fp, to end of file length

$instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img")));

 

Could someone help me out?

 

Thanks,

Sebastian

 

 

 

Please use code tags, your code makes my eyes bleed  :code_php_tags:

 

$fileName = $_FILES['imagefile']['name']; 
$tmpName  = $_FILES['imagefile']['tmp_name']; 
$fileSize = $_FILES['imagefile']['size']; 
$imtype = $_FILES['imagefile']['type']; 
@list(, , $imtype, ) = getimagesize($_FILES['imagefile']['tmp_name']); 
// Get image type. 
if ($imtype == 3) 
// cheking image type 
$imageextension="png";   
// to use it later in HTTP headers 
elseif ($imtype == 2) 
$imageextension="jpeg"; 
elseif ($imtype == 1) 
$imageextension="gif";
else 
$msg = 'Error: unknown file format'; 

$fp = fopen($tmpName, 'r+'); 
$content = fread($fp, filesize($tmpName)); 
//reads $fp, to end of file length
$instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img")));

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.