WordPress.org

Ready to get started?Download WordPress

Forums

OT: Help with this PHP code please (8 posts)

  1. Anonymous
    Unregistered
    Posted 10 years ago #

    Hi there,
    I am trying to use the function below but I keep getting a parse error.
    <pt>
    function download($path)
    global $HTTP_USER_AGENT;
    $file=basename($path);
    $size = filesize($path);
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/force-download");
    header("Content-Length: $size");
    // IE5.5 just downloads index.php if we don't do this
    if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT))
    header("Content-Disposition: filename=$file");
    } else
    header("Content-Disposition: attachment;
    filename=$file");
    }
    header("Content-Transfer-Encoding: binary");
    $fh = fopen($path, "r");
    fpassthru($fh);
    }
    I call it with this:
    <pt>
    <?php
    download('path/to/file.pdf');
    ?>
    The error I get is this: Parse error: parse error, expecting `'{'' in /home/public_html/download/download.php on line 11
    Anyu ideas?
    Thanls
    </pt>
    </pt>

  2. idahocline
    Member
    Posted 10 years ago #

    a { is missing at the beginning of the function - after function download($path)
    Just have a try....

  3. Anonymous
    Unregistered
    Posted 10 years ago #

    Thanks for that, I made that change and then I get a parse error on line 21 saying : Parse error: parse error in /home/public_html/download/download.php on line 21
    Line 21 is this:
    <pt>
    } else
    </pt>
    Thanks again.

  4. idahocline
    Member
    Posted 10 years ago #

    same { after "} else"

  5. Anonymous
    Unregistered
    Posted 10 years ago #

    Darn that still creates the error for { else
    Thanks

  6. carthik
    Member
    Posted 10 years ago #


    function download($path)
    {
    global $HTTP_USER_AGENT;
    $file=basename($path);
    $size = filesize($path);
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/force-download");
    header("Content-Length: $size");
    // IE5.5 just downloads index.php if we don't do this
    if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT))
    {
    header("Content-Disposition: filename=$file");
    }
    else
    {
    header("Content-Disposition: attachment;
    filename=$file");
    }
    header("Content-Transfer-Encoding: binary");
    $fh = fopen($path, "r");
    fpassthru($fh);
    }

    should fix it, for sure :)

  7. Anonymous
    Unregistered
    Posted 10 years ago #

    Hey there,
    Thanks for that :)
    It's getting there, I now get these errors:
    <qt>
    Warning: Cannot modify header information - headers already sent by (output started at /home/thenyton/public_html/download/thefile.php:36) in /home/thenyton/public_html/download/thefile.php on line 8
    Warning: Cannot modify header information - headers already sent by (output started at /home/thenyton/public_html/download/thefile.php:36) in /home/thenyton/public_html/download/thefile.php on line 9
    Warning: Cannot modify header information - headers already sent by (output started at /home/thenyton/public_html/download/thefile.php:36) in /home/thenyton/public_html/download/thefile.php on line 10
    Warning: Cannot modify header information - headers already sent by (output started at /home/thenyton/public_html/download/thefile.php:36) in /home/thenyton/public_html/download/thefile.php on line 19
    Warning: Cannot modify header information - headers already sent by (output started at /home/thenyton/public_html/download/thefile.php:36) in /home/thenyton/public_html/download/thefile.php on line 21
    %PDF-1.3 %âã?Ó 1 0 obj << /Filter[/FlateDecode] /Length 750 >> stream X…‘?OÓp@oꕃ??Àv’ ˜Õ?Øg›@bY·²Äƒ™k»Edë¯0‚?Œ¶ L¦]»#¶n|D!e° 11??&4•àXâÅŸzpÇ]%¾ä?_òlnÂNWÑþKÈ?V³? ]]N×…»:®ÚÌF£å¢)ÄÓç"?MûyÊ?†F†ƒBLXüxÿ¹Üé¦0’–ÒZõøW~Gx*¶¢Úp§ÉËØ)@øÙî'‚?ÜÈj•B¾òI¯Ã„ÿ=…Nj?•µ½ñÔî³¥íåÒ×µÔn1úzYYË&d9‘?Sïh–£,‚c]Ø@‡Ãº½ÿ}ïèGpnÉFQíž~wˆãðq<ÑkễQÛ?ªZÈn–DI?®ê¿Ml??–?!nvt|±rxëpç[jn#Ÿ+TrÇÕ>eHøÈǃÞƒ‘â\4ãί?…¨&F3Ù•rr|!š?a8%0¹ ^ä&Þ°??ÂS¤Sd(ž!M×aý,–‰Oj«zÌóÈŠæ̨QL„8—…´¶á2D\6?äg(QŒ‹›§X?æ¥t?ùœx›ÌÄȈ“]úì¾?9&qV‡ù´ôEæ8‘eí´–-ïM%¼W–2úêÑñÂ{ÓÃ>¨î|O—Z?&#Þ{??N̦•€ïŠÅT.Vàú?*òh?¨m.sCbs‡P»?~6@Š*~ž €£Åx]W³þ8I0v4èè°›Š,(©òËXQMË¢XȪûÕ’0¥$À:?ìcÌŽ{·q¯*O#žÂe•p¸¢Ê aŒG[ µž»f(ííBX?{#™ãƒj£Ù¨éG›M1á=o40ÓèÄ<ц#¸i÷ô¶š?†¦¾ÊiK?8Ò€?OûÅâ¦úq%9Ÿ?c,°T´\Jö½˜íËe&@¤ïËEç?Þös cÛR¦—b˜®­fƒúV^M Ào–Xû?ß$r–X¤WAÂDÌÿ‹šŽÅendstream endobj 2 0 obj [/Indexed/DeviceRGB 253 1 0 R] endobj 3 0 obj << /BitsPerComponent 8 /ColorSpace 2 0 R /Filter[/FlateDecode] /Subtype/Image /Height 219 /Type/XObject /Length 42775 /Width 250 >> stream X…T¹ C“gš÷}%áŠ\ä 0BB
    </qt>
    Am I placing the code in tjhe wrong location?
    This is a link to the page with the above code on: http://www.nuveautek.com/pdf_download_code.txt
    As you can see I am no developer when it comes to PHP.
    Thank you for your help
    Kathy

  8. Anonymous
    Unregistered
    Posted 9 years ago #

    header("Content-Type: application/octet-stream");
    header("Content-Type: application/force-download");
    -- Use one or the other, not both.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.