Results 1 to 6 of 6

php downloading code

This is a discussion on php downloading code within the PHP forums, part of the Courses category; can anyone help me in php language my problem is that as i click on download button the following item ...

  1. #1
    iTT Student
    Join Date
    Oct 2009
    Location
    pakistan
    Age
    32
    Posts
    2

    php downloading code

    can anyone help me in php language
    my problem is that as i click on download button the following item download automatically by any default browser plz send me the code as soon as possible i shall be very thankful to u.

  2. #2
    Senior Student
    Join Date
    Mar 2010
    Location
    pa
    Posts
    99

    Re: php downloading code

    mein aap ki baat samjha nahi. plz tell me in detail. jab aap download button ko press karen ge tu file download hi hogi na
    AIOU Old Papers
    http://aioucheats.com
    Pakistan Web Portal
    http://superwebportal.com

  3. #3
    iTT Student
    Join Date
    May 2010
    Location
    Mansehra Pakistan
    Age
    30
    Posts
    1

    Re: php downloading code

    nai php me file downloading ka script likhtay hain let me share with you my own code


    me ne actually 2 files banai aik me downloading ka link dia jo dosri file me moujood downloading script ko point karta hay


    filedownload.zipindex.php




    1. <html>
    2. <head>
    3. <title>Home</title>
    4. </head>
    5. <body>
    6. <a href="downloads.php?filename=codeigniter_helper_re ference.pdf">Download</a>
    7. </body>
    8. </html>


    download.php


    1. <?php
    2. // If user click the download link
    3. if(isset($_GET['filename'])){
    4. // The directory of downloadable files
    5. // This directory should be unaccessible from web
    6. $file_dir="files/";
    7. // Replace the slash and backslash character with empty string
    8. // The slash and backslash character can be dangerous
    9. $file_name=str_replace("/", "", $_GET['filename']);
    10. $file_name=str_replace("\\", "", $file_name);
    11. // If the requested file is exist
    12. if(file_exists($file_dir.$file_name)){
    13. // Get the file size
    14. $file_size=filesize($file_dir.$file_name);
    15. // Open the file
    16. $fh=fopen($file_dir.$file_name, "r");
    17. // Download speed in KB/s
    18. $speed=200;
    19. // Initialize the range of bytes to be transferred
    20. $start=0;
    21. $end=$file_size-1;
    22. // Check HTTP_RANGE variable
    23. if(isset($_SERVER['HTTP_RANGE']) &&
    24. preg_match('/^bytes=(\d+)-(\d*)/', $_SERVER['HTTP_RANGE'], $arr)){
    25. // Starting byte
    26. $start=$arr[1];
    27. if($arr[2]){
    28. // Ending byte
    29. $end=$arr[2];
    30. }
    31. }
    32. // Check if starting and ending byte is valid
    33. if($start>$end || $start>=$file_size){
    34. header("HTTP/1.1 416 Requested Range Not Satisfiable");
    35. header("Content-Length: 0");
    36. }
    37. else{
    38. // For the first time download
    39. if($start==0 && $end==$file_size){
    40. // Send HTTP OK header
    41. header("HTTP/1.1 200 OK");
    42. }
    43. else{
    44. // For resume download
    45. // Send Partial Content header
    46. header("HTTP/1.1 206 Partial Content");
    47. // Send Content-Range header
    48. header("Content-Range: bytes ".$start."-".$end."/".$file_size);
    49. }
    50. // Bytes left
    51. $left=$end-$start+1;
    52. // Send the other headers
    53. header("Content-Type: application/octet-stream");
    54. header("Accept-Ranges: bytes");
    55. // Content length should be the bytes left
    56. header("Content-Length: ".$left);
    57. header("Content-Disposition: attachment; filename=".$file_name);
    58. // Read file from the given starting bytes
    59. fseek($fh, $start);
    60. // Loop while there are bytes left
    61. while($left>0){
    62. // Bytes to be transferred
    63. // according to the defined speed
    64. $bytes=$speed*1024;
    65. // Read file per size
    66. echo fread($fh, $bytes);
    67. // Flush the content to client
    68. flush();
    69. // Substract bytes left with the tranferred bytes
    70. $left-=$bytes;
    71. // Delay for 1 second
    72. sleep(1);
    73. }
    74. }
    75. fclose($fh);
    76. }
    77. else{
    78. // If the requested file is not exist
    79. // Display error message
    80. echo "File not found!";
    81. }
    82. exit();
    83. }
    84. ?>



    baqi aap daikh lain attachement b kardi hay me ne

  4. #4
    iTT Student
    Join Date
    Jan 2013
    Location
    Mianwali
    Age
    29
    Posts
    19

    Re: php downloading code

    main yaha new hoo ye php kine din me seekhi ja sagti hy

  5. #5
    iTT Student
    Join Date
    Jan 2013
    Location
    Mianwali
    Age
    29
    Posts
    19

    Re: php downloading code

    plz tell me main php sikhna chahta hoo main itna janta b nai hoo abhi abhi net per new aya hoo agr bilkul shuru se seekhna chahoo to kine din lage ge

  6. #6
    iTT Student sohailahmedblog's Avatar
    Join Date
    Mar 2013
    Location
    Taxila
    Age
    27
    Posts
    22

    Re: php downloading code

    Zahid ye ap pe depend karta hai apka shoq kitna hai, minimum 3months me ap seekh sakty hain not complete it depends on prctice:-)

Similar Threads

  1. Html Code,Free Resource,Free Code,Free Template
    By Tring in forum Website Reviews
    Replies: 16
    Last Post: 27th January 2011, 06:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •