Php Curl ile Instagram Resim İndirme | Turkish Tutorial

in #utopian-io7 years ago

English Description

Hello friends In this article I will try to tell you how to download the images published in instagram with php and give them to the user visually.

First of all, let's talk about how we're going to do something. With the help of html form tags, the instagram will post the url information in the image. We will check if the url information of the instagram image is checked with if control. If it is posted, we will connect to the image source page with the image cURL and get the url information of the image, then we will link to the source in this image and download the instagram image. The functions we will use are isset, preg_match, uniqid, file_put_contents. I will include in detail below how these functions are used and how they are used. I hope it will be useful for you.

Türkçe Açıklama

Merhaba arkadaşlar bu yazımda sizlere php ile instagramda ki yayınlanan resimleri nasıl sunuzumuza indirip kullanıcıya veririz görsel şekilde anlatmaya çalışacağım.

Öncelikle nasıl birşey yapacağımızdan bahsedelim. Html form etiketlerinin yardımı ile instagram resim url bilgisini post ettireceği. if kontrolü ile instagram resim url bilgisinin post edilip edilmediğini kontrol edeceğiz eğer post edilmişse resim curl ile resim kaynak sayfasına bağlanıp resmin url bilgisini alacağız daha sonra bu resminde kaynağına bağlanıp instagram resmini indireceğiz. Yararlanacağımız fonksiyonlar isset, preg_match, uniqid, file_put_contents fonksiyonlarıdır. Bu fonksiyonların ne işe yaradığınız nasıl kullanıldığına aşağıda detaylı şekilde yer vereceğim. Umarım sizler için yararlı olur.

Yararlanacağımız fonksiyonlar;

isset — Değişken tanımlı mı diye bakar. Giriye True veya False yanıtı döndürür.
preg_match — Bir düzenli ifadeyi eşleştirmeye çalışır. Bir ise verdiğimiz reqex desenine göre istediğimiz bölümü alacağız.
uniqid — Eşsiz bir kimlik dizgesi üretir
file_put_contents — Bir dizgeyi bir dosyaya yazar

Github Proje Linki;

Github Project.png
https://github.com/Ruhum36/Instagram-Image-Save-Script

index.php

<?php
    ### Coded By Ruhum 20.12.2017
    require('Fonksiyonlar.php');
?>

<!DOCTYPE html>
<html>
<head>
    <title>Instagram Image Save</title>
    <style type="text/css">
        
        *{
            font-family: arial;
            background-color: #effffe;
        }

    </style>
</head>
<body>

<div>
    
    <center><h2>Instagram Image Save</h2></center>

    <form action="" method="POST" style="width: 500px; margin: auto;">
            
        <input type="text" name="ImageUrl" style="padding: 10px; width: 450px; border-radius: 3px; border: 1px solid #ddd;" placeholder="Image URL" /><br />
        <input type="submit" value="Save Image" style="padding: 10px; width: 470px; border-radius: 3px; border: 1px solid #ddd; background-color: #f6f6f6; margin-top: 10px;" />

    </form>

</div>

<?php
    
    if(isset($_POST['ImageUrl'])){

    $Url = $_POST['ImageUrl'];
    $Source = Connect($Url);
    $Image = preg_match('@image" content="(.*?)"@', $Source, $Image)?end($Image):false;

        if($Image){

            $ImageName = 'images/'.uniqid().'.jpg';
            $ImageSource = Connect($Image);
            if(file_put_contents($ImageName, $ImageSource)){

                echo '<center><h2>Image Saved</h2></center>';
                echo '<center><img src="'.$ImageName.'" width="500" /></center>';
    
            }

        }else{

            echo '<center><h2>Image Not Found or Private</h2></center>';

        }

    }

?>

</body>
</html>

Fonksiyonlar.php

<?php

    function Connect($Url, $TimeOut = 10, $UserAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0'){

        $Curl = curl_init(); 
        curl_setopt($Curl, CURLOPT_URL, $Url);
        curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($Curl, CURLOPT_USERAGENT, $UserAgent);
        curl_setopt($Curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($Curl, CURLOPT_TIMEOUT, $TimeOut);
        curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER, false);
        $Sonuc = curl_exec($Curl);
        curl_close($Curl);

        return $Sonuc;

    }

?>

Genel Görseller;

Codes Instagram Image.png

InstagramImageSave 1.png

Kodlar ve Açıklamaları;

Screenshot_8.png

    <center><h2>Instagram Image Save</h2></center>

    <form action="" method="POST" style="width: 500px; margin: auto;">
            
        <input type="text" name="ImageUrl" style="padding: 10px; width: 450px; border-radius: 3px; border: 1px solid #ddd;" placeholder="Image URL" /><br />
        <input type="submit" value="Save Image" style="padding: 10px; width: 470px; border-radius: 3px; border: 1px solid #ddd; background-color: #f6f6f6; margin-top: 10px;" />

    </form>

Bu kısımda instagram resim url bilgisini alabilmek için standart html etiketleri yardımı ile formumuzu oluşturuyoruz.

Screenshot_9.png

    if(isset($_POST['ImageUrl'])){

    $Url = $_POST['ImageUrl'];
    $Source = Connect($Url);
    $Image = preg_match('@image" content="(.*?)"@', $Source, $Image)?end($Image):false;

        if($Image){

            $ImageName = 'images/'.uniqid().'.jpg';
            $ImageSource = Connect($Image);
            if(file_put_contents($ImageName, $ImageSource)){

                echo '<center><h2>Image Saved</h2></center>';
                echo '<center><img src="'.$ImageName.'" width="500" /></center>';
    
            }

        }else{

            echo '<center><h2>Image Not Found or Private</h2></center>';

        }

    }

Kodların açıklamasını resimde görünen satır sayıları var. O sayıları baz alarak size kodların açıklamalarını yapmaya çalışacağım.

-36. Satır: isset yardımı ile instagram resim url bilgisi post edilmiş mi diye kontrol ediyoruz. isset bize boolean değer çevirdiği için bunuda if ile kontrol ediyoruz.

-39. Satır: Gelen url bilgisine connect fonksiyonumuz ile bağlanıyoruz.

-40. Satır: preg_match fonksiyonun yardımı ile instagramdaki resmin url adresini alıyoruz. Bunuda $Image değikenine aktarıyoruz. Eğer herhangi bir değer bulamazsa false $Image değişkenine false değerini atayacaktır.

-42. Satır: Resim url varmı yokmu diye kontrol ediyoruz.

-44. Satır: uniqid fonksiyonu ile yeni bir resim adı oluşturuyoruz.

-45. Satır: Resim url adresine bağlanarak kaynak kodlarını $Source değişkenine aktarıyoruz.

-46. Satır: file_put_contents yardımı ile aldığımız resmin kaynağını sunucuya belirttiğimiz isimde yazdırıyoruz.

-48. 49. Satır: Yazılan resim sonucu ve sunucuya yazdırdığımız resmi ekrana yazdırıyoruz.

Aklınıza takılan soru olursa, önerileriniz, anlatmamı istediğiniz bir eğitim içeriği varsa lütfen konu altında bana bildirin. Elimden geleni seve seve yaparım. Umarım hepiniz için yararlı bir konu olmuştur.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @ruhum I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.028
BTC 54225.25
ETH 2280.38
USDT 1.00
SBD 2.29