1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[ASK] script php untuk downlad link file pdf secara langsung save file

Discussion in 'Pemrograman Web' started by shelfie, Jun 4, 2016.

  1. shelfie

    shelfie Super Hero

    Joined:
    Aug 3, 2010
    Messages:
    1,911
    Likes Received:
    301
    selamat siang kawan2 ..

    langsung saja, nyubi sedang buat blog ebook berupa dan filenya adalah file type pdf.
    Nah penginnya ketika pengunjung klik link download langsung save file /langsung download, tidak buka file pdfnya dulu via browser,

    Kemarin sudah coba search di internet dan dapat script ini :

    1. file pdfserver.php
    PHP:
    <?php
    header
    ("Content-Type: application/octet-stream");

    $file $_GET["file"] .".pdf";
    header("Content-Disposition: attachment; filename=" urlencode($file));   
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Description: File Transfer");            
    header("Content-Length: " filesize($file));
    flush(); // this doesn't really matter.
    $fp fopen($file"r");
    while (!
    feof($fp))
    {
        echo 
    fread($fp65536);
        
    flush(); // this is essential for large downloads

    fclose($fp); 
    ?>
    file html downloadnya :
    download.html

    HTML:
    
    <html>
    <head>
    </head>
    <body>
    <a href="pdfserver.php?file=httpxxxx://domain.com/contoh.pdf">Download my eBook</a>
    </body>
    </html>
    

    Permasalahan :
    script tersebut ketika ane coba di locolhost [komputer ane], running dengan baik, tetapi ketika ane upload di hosting, tidak jalan dan tidak bisa download

    Pertanyaan :
    1. Kenapa script tersebut di hosting tidak bisa jalan [tidak bisa download file, sementara pdfnya ada]
    2. Mohon pencerahan agar script tersebut bisa running, harus seperti apa scriptnya...

    Terima kasih kawan2...
     
  2. dewaz

    dewaz Super Hero

    Joined:
    Sep 24, 2009
    Messages:
    1,523
    Likes Received:
    211
    Location:
    bali
    (1) $file = $_GET["file"] .".pdf";

    (2) pdfserver.php?file=httpxxxx://domain.com/contoh.pdf

    dengan cara ini $file dapetnya httpxxxx://domain.com/contoh.pdf kan?
    Nah, itu hyperlink dan bukan folder, makanya gak bisa.

    Ada cara simple yang lebih mudah untuk aplikasinya.

    Upload saja file yang dimaksud ke mediafire, 4shared, google cloud, hotmail cloud ... semua gratis
    taruh link nya sebagai link donlot.

    itu lebih simple dan aplicable.
     
  3. shelfie

    shelfie Super Hero

    Joined:
    Aug 3, 2010
    Messages:
    1,911
    Likes Received:
    301
    terima kasih gan...
    1. Iya gan, memang $file dapetnya httpxxxx://domain.com/contoh.pdf, nah keinginan ane itu langsung download gan, seperti pada file berekstensi .doc, .zip kan langsung download, seperti <a href="httpxxxx://domain.com/contoh.doc">download</a>

    Nah kalo pdf itu biasanya membuka dulu filenya, kemudian baru bisa dibuka...
    script tersebut diterapkan di localhost jadi gan, tetapi ketika script di atas ane upload ke hosting


    2. Ane penginnya file tersebut berada di hosting sendiri gan
     
  4. Daeng Faroqi

    Daeng Faroqi Newbie

    Joined:
    Sep 17, 2016
    Messages:
    7
    Likes Received:
    0
    Location:
    Jakarta
    <a href="filepdf.pdf" download></a>

    harusnya gt aj x y
     
  5. iwiel2

    iwiel2 Ads.id Pro

    Joined:
    Oct 4, 2016
    Messages:
    360
    Likes Received:
    9
    Pake cara ini bisa kalau file ini static (bukan buffer) CMIIW
     

Share This Page