Php ile Dosya Yükleme| Turkish Tutorial

in #utopian-io7 years ago (edited)

English Description

Hello friends In this article I will try to tell you how to upload files to php with our server visually.

First of all, let's talk about how we're going to do something. It will post our file with the help of HTML form tags. We will check if the file is posted with if control. If it is post, we will take the file name with the basename function and write it to our server with the move_uploaded_file function. The functions we will use are the isset, basename and move_uploaded_file functions. 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 sunucumuza dosya nasıl yüklenir görsel şekilde anlatmaya çalışacağım.

Öncelikle nasıl birşey yapacağımızdan bahsedelim. HTml form etiketlerinin yardımı ile dosyamızı post ettireceği. if kontrolü ile dosyanın post edilip edilmediğini kontrol edeceğiz eğer post edilmişse basename fonksiyonu ile dosya adını alıp move_uploaded_file fonksiyonu ile sunucumuza yazdıracağız. Yararlanacağımız fonksiyonlar isset, basename ve move_uploaded_file 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.
basename = Dosya yolunun sadece dosya ismi bileşenini döndürür.
move_uploaded_file = Tmp yolundaki dosyayı sunucuya taşır.

Github Proje Linki;

Github Project.png
https://github.com/Ruhum36/Php-File-Upload

<!DOCTYPE html>
<html>
<head>
    <title>Php File Upload</title>
    <style type="text/css">
        
        *{
            font-family: arial;
            background-color: #d4f2ff;
        }
        #FileName{
            padding: 10px; width: 450px; border-radius: 3px; border: 1px solid #ddd;
        }

    </style>
</head>
<body>

    <center><h2>Php File Upload</h2></center>
    <form action="" method="POST" style="width: 585px; margin: auto;" enctype="multipart/form-data">
            
        <input type="file" name="File" id="FileName" />
        <input type="submit" name="FileUpload" value="Upload File" style="padding: 12px; width: 100px; border-radius: 3px; border: 1px solid #ddd; background-color: #f6f6f6; margin-top: 10px;" /><br /><br />

    </form>

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

        $DirFolder = './files/';
        $UploadFile = $DirFolder. basename($_FILES['File']['name']);

        if (move_uploaded_file($_FILES['File']['tmp_name'], $UploadFile)){

            echo "<center>File is valid, and was successfully uploaded.</center>";

        } else {

            echo "<center>Possible file upload attack!</center>";

        }

    }

?>

</body>
</html>

Genel Görseller;

Resim 2.png

Resim 1.png

Kodlar ve Açıklamaları;

Screenshot_6.png

    <center><h2>Php File Upload</h2></center>
    <form action="" method="POST" style="width: 585px; margin: auto;" enctype="multipart/form-data">
            
        <input type="file" name="File" id="FileName" />
        <input type="submit" name="FileUpload" value="Upload File" style="padding: 12px; width: 100px; border-radius: 3px; border: 1px solid #ddd; background-color: #f6f6f6; margin-top: 10px;" /><br /><br />

    </form>

Html form etiketleri yardımı ile formumuzu oluşturuyoruz. Burada dikkat etmeniz gereken, kısım normal form oluşturmalar da " enctype="multipart/form-data" " html etiketi kullanılmaz veri post ediliğinde de sonuç alınmaz. Eğer dosya yükleyecekseniz enctype="multipart/form-data" etiketini girmek zorundasınız.

Screenshot_7.png

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

        $DirFolder = './files/';
        $UploadFile = $DirFolder. basename($_FILES['File']['name']);

        if (move_uploaded_file($_FILES['File']['tmp_name'], $UploadFile)){

            echo "<center>File is valid, and was successfully uploaded.</center>";

        } else {

            echo "<center>Possible file upload attack!</center>";

        }

    }

Burayı satır satır anlatacağım. isset fonksiyonu ile dosyanın post edilip edilmediğini kontrol ediyoruz eğer post edilmişse if blokuna edilmemişse else blokuna düşmesini sağlıyoruz.

-31. Satır: Burada dosyanın hangi klasöre yükleneceğini belirliyoruz
-32. Satır: Bu kısımda php'nin kendi sağladığı basename fonksiyonun yardımı ile post edilen dosyanın adını alıyoruz.
-34. Satır: Burada move_uploaded_file yardımı ile dosyamızı sunucuya yüklüyoruz. move_uploaded_file fonksiyonu 2 parametre alır 1. parametrede dosyanın tmp yolu 2. parametrede ise nereye yükleneceği ve dosyaya vermek istediğiniz isim.
-36.- 40. Satır: Sonucu if ile kontrol edip sonucu echo ile ekrana bası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 54391.40
ETH 2283.95
USDT 1.00
SBD 2.29