Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Hai i want a small help regarding this

    Hai all,
    I wrote an php script to download a file.But i am getting an error unable to open a file.I hosted the file in the server at a specific folder.At the time of downloading it is downloading a file but the data in that file is not displaying.
    please can anyone help on this.

  • #2
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    please post the exact error message and the script that you are using to do this

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i am sending the code
    please check it
    <?php

    $file_name = $_POST['file'];
    $file_path = "/home/spherete/public_html/";
    header("Content-Type: application/unknown");
    header("Content-Disposition: filename=$file_name");

    if($fp = fopen($file_path.$file_name, "r"))
    {
    while(!feof($fp)) {
    echo fgets($fp, 4096);
    }
    fclose($fp);

    }
    ?>

    After executing this code i am getting the file to save but in the file there is no content and giving the error as below:

    Warning: fopen(/home/spherete/public_html/index.php ) [function.fopen]: failed to open stream: No such file or directory in /home/spherete/public_html/download.php on line 12

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
    $file_name $_POST['file'];
    $file_path "/home/spherete/public_html/";
    header("Content-Type: application/unknown");
    header("Content-Disposition: filename=$file_name");

    if(
    $fp fopen($file_path.$file_name"r")) 
    That is a security hole. Don't just plainly take a filename parameter through POST/GET without doing any kind of cleaning.

    Also, do not use an absolute file path such as /home/spherete/public_html. Try to use a relative path whenever possible (which is almost always).

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanku for ur advice.
    we already changed that path. Coming to get and post methods with out that how can we get the file name.To get file name we have to use any one thing.Did you see the error what i am getting.
    Can you tell me how to solve that error.
    please help me i am new to php and i am not getting how to do this.

    Thanking you,


    Quote Originally Posted by aedrin View Post
    That is a security hole. Don't just plainly take a filename parameter through POST/GET without doing any kind of cleaning.

    Also, do not use an absolute file path such as /home/spherete/public_html. Try to use a relative path whenever possible (which is almost always).


  •  

    Posting Permissions

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