download file problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manirajmurali
    New Member
    • Apr 2007
    • 2

    download file problem

    hi all,

    i have face this problem more 3 days.. if anybody help me..

    i have upload file through php coding .. i have download that same file from server..
    its coming empty file.. i dont know why its coming... its correctly working in local system.. but not working server. Linux server
    its very urgent.. pls reply me.
    [php]
    Its Upload coding:
    --------------------------
    <?php
    $target_path = "uploads/";
    $target_path = $target_path . basename( $_FILES["attachment "]["name"]);

    if(move_uploade d_file($_FILES["attachment "]["tmp_name"], $target_path)) {
    echo "The file ". basename( $_FILES["attachment "]["name"]).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }
    ?>[/php]
    Its download coding :[php]
    <?php
    ob_start();
    $dirfile=$_REQU EST['file'];
    $file=basename( $dirfile);
    $dir = "../uploads/";
    if ((isset($file)) &&(file_exists( $dirfile))) {
    header("Content-type: application/force-download");
    header('Content-Disposition: inline; filename="' . $dirfile . '"');
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($dir file));
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $dirfile . '"');
    readfile("$dirf ile");

    } else {
    echo "No file selected";
    }
    ?>[/php]--------------------------
    by
    Karthik
    Last edited by ronverdonk; Mar 3 '08, 02:14 PM. Reason: adding code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Do you not have to give the right content type?
      ie. image/jpeg application/pdf

      Comment

      Working...