• 11-05-2016, 20:41:41
    #1
    Merhabalar,

    Resim dosyalarını şu şekilde download ettiriyorum.

    <?php
    session_start();
    $file = $_GET['file']; 
     
    	download_file($file); 
    function download_file( $fullPath ){
    
      // Must be fresh start
      if( headers_sent() )
        die('Headers Sent');
    
      // Required for some browsers
      if(ini_get('zlib.output_compression'))
        ini_set('zlib.output_compression', 'Off');
    
      // File Exists?
      if( file_exists($fullPath) ){
    
        // Parse Info / Get Extension
        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);
        $ext = strtolower($path_parts["extension"]);
    
        // Determine Content Type
        switch ($ext) {
          case "pdf": $ctype="application/pdf"; break;
          case "exe": $ctype="application/octet-stream"; break;
          case "zip": $ctype="application/zip"; break;
          case "doc": $ctype="application/msword"; break;
          case "xls": $ctype="application/vnd.ms-excel"; break;
          case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
          case "gif": $ctype="image/gif"; break;
          case "png": $ctype="image/png"; break;
          case "jpeg":
          case "jpg": $ctype="image/jpg"; break;
          default: $ctype="application/force-download";
        }
    
        header("Pragma: public"); // required
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false); // required for certain browsers
        header("Content-Type: $ctype");
        header("Content-Disposition: attachment; filename=\"".$_REQUEST["isim"]."\";" );
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".$fsize);
        ob_clean();
        flush();
        readfile( $fullPath );
    
      } else
        die('File Not Found');
    
    }
    ?>
    şu şekilde linke gidince resim dosyası gayet güzel iniyor.
    http://domain.net/download.php?file=wp-content/uploads/2016/04/10/126379-fantasy_art.jpg

    fakat bu şekilde gidince wp-config dosyası da iniyor. http://domain.net/download.php?file=wp-config.php

    php dosyaların inmesini istemiyorum. bunu nasıl engelleyebilirim?

    Teşekkürler
  • 11-05-2016, 21:03:46
    #2
    .htaccess içine şunu ekleyin
    <Files ~ "\.php$">
    Order allow,deny
    Deny from all
    </Files>
  • 11-05-2016, 21:09:52
    #3
    s7e7v7e7n7 adlı üyeden alıntı: mesajı görüntüle
    Merhabalar,

    Resim dosyalarını şu şekilde download ettiriyorum.

    <?php
    session_start();
    $file = $_GET['file']; 
     
    	download_file($file); 
    function download_file( $fullPath ){
    
      // Must be fresh start
      if( headers_sent() )
        die('Headers Sent');
    
      // Required for some browsers
      if(ini_get('zlib.output_compression'))
        ini_set('zlib.output_compression', 'Off');
    
      // File Exists?
      if( file_exists($fullPath) ){
    
        // Parse Info / Get Extension
        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);
        $ext = strtolower($path_parts["extension"]);
    
        // Determine Content Type
        switch ($ext) {
          case "pdf": $ctype="application/pdf"; break;
          case "exe": $ctype="application/octet-stream"; break;
          case "zip": $ctype="application/zip"; break;
          case "doc": $ctype="application/msword"; break;
          case "xls": $ctype="application/vnd.ms-excel"; break;
          case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
          case "gif": $ctype="image/gif"; break;
          case "png": $ctype="image/png"; break;
          case "jpeg":
          case "jpg": $ctype="image/jpg"; break;
          default: $ctype="application/force-download";
        }
    
        header("Pragma: public"); // required
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false); // required for certain browsers
        header("Content-Type: $ctype");
        header("Content-Disposition: attachment; filename=\"".$_REQUEST["isim"]."\";" );
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".$fsize);
        ob_clean();
        flush();
        readfile( $fullPath );
    
      } else
        die('File Not Found');
    
    }
    ?>
    şu şekilde linke gidince resim dosyası gayet güzel iniyor.
    http://domain.net/download.php?file=wp-content/uploads/2016/04/10/126379-fantasy_art.jpg

    fakat bu şekilde gidince wp-config dosyası da iniyor. http://domain.net/download.php?file=wp-config.php

    php dosyaların inmesini istemiyorum. bunu nasıl engelleyebilirim?

    Teşekkürler
    Şu şekilde olabilir. Dosya uzantısı php ise indirme tarzında.
        $ext = strtolower($path_parts["extension"]);
         if( $ext == "php" ) die("Cannot be downloaded!!!");
  • 11-05-2016, 21:20:33
    #4
    arkadaşlar cevaplar için çok teşekkür ederim.

    default: $ctype="application/force-download";
    şu kodu
    default: die('File not found');
    bununla değiştirince sorun çözüldü..

    Tekrardan çok teşekkürler

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 21:20:33 -->-> Daha önceki mesaj 21:15:08 --

    inspectorrr adlı üyeden alıntı: mesajı görüntüle
    Şu şekilde olabilir. Dosya uzantısı php ise indirme tarzında.
        $ext = strtolower($path_parts["extension"]);
         if( $ext == "php" ) die("Cannot be downloaded!!!");
    Evet hocam sizinki de çözüm oluyormuş. Ben garanti olsun diye sizinkisini de ekledim
  • 11-05-2016, 21:25:12
    #5
    s7e7v7e7n7 adlı üyeden alıntı: mesajı görüntüle
    arkadaşlar cevaplar için çok teşekkür ederim.

    default: $ctype="application/force-download";
    şu kodu
    default: die('File not found');
    bununla değiştirince sorun çözüldü..

    Tekrardan çok teşekkürler

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 21:20:33 -->-> Daha önceki mesaj 21:15:08 --



    Evet hocam sizinki de çözüm oluyormuş. Ben garanti olsun diye sizinkisini de ekledim
    Aslında yaptığınız şey aynı mantığa geliyor benim yaptığımda sadece php dosyalarını kapatıyor, sizin çözüm daha güzel oradaki uzantılar hariç diğerlerinde hata verecek ve indirmeyecektir.