function curl_file_get_daiphocontents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } $domainname = 'https://www.daipho.com'; $url = $domainname .'/logo/image-6-1.png'; $img = 'daipho-6-1.png'; $data = curl_file_get_daiphocontents($url); file_put_contents( $img, $data ); echo "Đã lưu tập tin ". $img ." từ ". $domainname ."!";
Saving Image from URL cURL code
Tiêu đề: | Saving Image from URL cURL code |
---|---|
Alt: | Đoạn code luu hinh anh tu url trong php bang thu vien curl |
Chú thích: | |
Type: | image/png |
Mô tả: | function curl_file_get_daiphocontents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } $domainname = 'https://www.daipho.com'; $url = $domainname .'/logo/image-6-1.png'; $img = 'daipho-6-1.png'; $data = curl_file_get_daiphocontents($url); file_put_contents( $img, $data ); echo "Đã lưu tập tin ". $img ." từ ". $domainname ."!"; |
Uploaded To:
Đôi khi, chúng ta cần tải xuống một hình ảnh từ một URL cụ thể và sử dụng nó vào dự án nào đó. Một cách dễ dàng là truy cập URL đó, nhấp chuột phải và lưu hình…