Forum Zero
ForumZero

PHP ile Dosya İndirme

0 Üye ve 1 Ziyaretçi konuyu incelemekte.

Çevrimdışı AStaLD

  • Kücük Üye
  • **
    • İleti: 64
    • Rep: 200
    • Cinsiyet:Bay
    • Profili Görüntüle
Mrb Arkadaşlar Geçenlerde nette Bulduğum paylaşımı Birazda geliştirirerek örnek haline getirip paylaşmak istedim kodlar sağlam denedim ama sadece .rar .zip. tar.gt vs. gibi dosyaları indirebiliyorsunuz dosyalarınızı JET hızda indiriyor şaşırdım :D ben dosyanın tam dizini yazıp indir tıklayın bir kaç saniye sonra bakın test/ klasörün içinde :d şaşırmayın bu php'nin güzel yanlarından biri neyse fazla uzatmadan sizlere kodları paylaşayım
bu sınıfmız

<?php
/* Php File Download v2.0
 * Yusuf KOÇ ( Raiden )
 * http://www.ysfkc.com
 *
 * Copyright 2008 Ysfkc.Com
 * Licensed under the GNU General Public License, version 2.
 * See the file http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 */

class fileDownload
{
    private $fileUrl;
    private $file;
    private $dir;
    private $curl;
    private $content;
    private $fileName;
    private $fileExtension;
    private $getMsg = array();
    
    public function setUrlAddress($url)
    {
        $this->fileUrl = $url;
    }
    
    public function setDirectory($name)
    {
        if (!is_writable($name) || !is_readable($name))
        {
            $this->getMsg[] = 'Belirtmiş Olduğunuz Dizin Yazılabilir Değil';
            $this->getMsg[] = 'Belirtmiş Olduğunuz Dizin Okunabilir Değil';
        }
        else
        {
            $this->dir = $name;
        }
    }
    
    public function setFileName($name)
    {
        if (is_bool($name) && $name === false)
        {
            $this->fileName = preg_replace("/^(http:\/\/.*\/)?/i",'',$this->fileUrl);
        }
        else if (is_bool($name) && $name === true)
        {
            $this->fileName = md5(sha1(uniqid(mt_rand().microtime()))).'.'.$this->getFileExtension();
        }
        else
        {
            $this->fileName = $name.'.'.$this->getFileExtension();
        }
    }
    
    private function getFileExtension()
    {
        return preg_replace('/^(http:\/\/.*\.)?/i','',$this->fileUrl);
    }

    private function getData()
    {
        $this->curl = curl_init();
        curl_setopt($this->curl,CURLOPT_URL, $this->fileUrl);
        curl_setopt($this->curl,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
        curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,1);
        $this->content = curl_exec($this->curl);
        curl_close($this->curl);
    }
    
    public function saveData()
    {
        # Callback getData()
        $this->getData();
        
        # Open new file
        $this->file = fopen($this->dir.'/'.$this->fileName,'w');
        
        if (fwrite($this->file,$this->content))
        {
            $this->getMsg[] = 'Dosya Kaydedildi.';
            $this->getMsg[] = 'Dosya Yolu: <i>'.$this->dir.'/'.$this->fileName.'</i>';
            return true;
        }
        else
        {
            $this->getMsg[] = 'Dosya Download Edilemedi';
            return false;
        }
    }
    
    public function getMessage()
    {
        echo '<ul>';
        foreach ($this->getMsg AS $value)
        {
            echo "\t<li>".$value."</li>\n";
        }
        echo '</ul>';
    }
}
?>


<?php
/* Php File Download v2.0
 * Forumzero.org
 * http://www.forumzero.org
 */

# Sınıfımızı Dahil Ediyoruz.
# -------------------------------
include_once('ysfkc.file.php');
$url    = $_POST['url'];
$yeniad  = $_POST['yeniad'];
if($_POST){
# Sınıfımızı Başlatıyoruz.
# -----------------------------
$file = new fileDownload;

# Download Etmek İstediğimiz Dosyayının URL Adresini Giriyoruz.
# -------------------------------------------------------------------
$file->setUrlAddress("$url");

# Download Edilecek Dizini Belirtiyoruz.
# ----------------------------------------
$file->setDirectory('test');

# Dosyaya Random İsim Verdiyoruz True Parametresini Girerek.
# False Direk ajax.tar.gz olarak alacaktır.
$file->setFileName("$yeniad"); //ile kendiniz de isim verebilirsiniz.
$file->setFileName(true);

# Son Olarak Dosya Kaydetme İşlemini Başlatıyoruz.
# ----------------------------------------------------------------
if ($file->saveData())
{
    # Download İşlemi Başarılı Oldu İse Bildirim Mesajını Alıyoruz.
    # ----------------------------------------------------------------
    $file->getMessage();
}
else
{
    # Download İşlemi Başarılı Olmadıysa Hata Bildirimini Yapıyoruz
    # ----------------------------------------------------------------
    $file->getMessage();
}
}
?>
<form method="post" action="">
<table>
<tr>
     <td>Site URL Uzantısı</td>
<td><input type="text" name="url" size="55px"/></td>
</tr>
<tr>
     <td>YeniAd</td>
<td><input type="text" name="yeniad" size="55px"/></td>
</tr>
<tr>
     <td></td>
<td><input type="submit" value="İndir"/></td>
</tr>
</table>
</form>


Veya İsterseniz Orjinal Kodları ile beraber Message to show when link is hided İndirebilirsiniz
Kodlar Alıntıdır.


Çevrimdışı AStaLD

  • Kücük Üye
  • **
    • İleti: 64
    • Rep: 200
    • Cinsiyet:Bay
    • Profili Görüntüle
verdiğim kodlar çalışmaktador bizzat kendim denedim ve kullanıyorum  #desteklemek2#