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

 

 

 

Link to comment
Share on other sites

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")));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.