Teya Salat
Hãy nhanh tay Đăng kí và Đăng nhập để trở thành thành viên chính thức của Vn3x.Yn.Lt và cùng thảo luận!
» » » Function Upload Ảnh Lên Imgur
Bạn phải để Bình luận

Function Upload Ảnh Lên Imgur

Forum GetSmile..! ↑ ↓
MinhNP * MinhNP (Member) [Off]
* 03-12-2016

Code này chả biết của ai nữa, cứ up lên cho m.n xem cho vui :kaka:

// Upload file lên imgur.com
 function md_up_file($link){
   $client_id="46ecc13f6a05d52"; 
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  
   curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json'); 
   curl_setopt($curl, CURLOPT_TIMEOUT, 30); 
   curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id)); 
   curl_setopt($curl, CURLOPT_POST, 1); 
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
   curl_setopt($curl, CURLOPT_POSTFIELDS, array('image' => base64_encode(file_get_contents($link)))); 
   $out = curl_exec($curl); 
   curl_close ($curl); 
   $pms = json_decode($out,true); 
   return $pms['data']['link'];
 }
 // Upload các hình ảnh có trong bài
 function md_up_files($data){
   preg_match_all('/\[img\](.+?)\[\/img\]/is', $data, $imgg);
   foreach($imgg[0] as $i=>$image){
   $img = str_replace('[img]', '',$image);  $img = str_replace('[/img]', '',$img);
   $data=str_replace($image, '[img]'.md_up_file($img).'[/img]', $data);
   }
   return $data;
 }

-----
Cách dùng : dán code lên trên , viết dòng này bên dưới
$noidung = md_up_files($noidung);

////Code php gắn vào tool thì ok con de////Nguồn: KhánhSociu :hi:

(0)
- Tổng số 1 bình luận và lượt xem

Online: [0]Khách: [1]
GetSmile..!Thiết kế bởi SINO-