Results 1 to 3 of 3

Thread: PHP Help Please

  1. #1
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default PHP Help Please

    Basically I was trying to make a download script where you put in the name of the file you wanted into a box, it looks for that file in one directory (always the same one, called /downloads/). I can't seem to get it to work though, it never finds the file properly. If anyone knows what they're doing, can they please help me? Thanks


    PHP Code:
    <html>
    <div align='center'><font size=20>DOWNLOADS</font></div>
    <br>
    Files available for download:<br>
    <ul>
    <li>testfile.txt
    </ul>

    <?php

    echo "<form method='post' action='download.php'>
    <input name='file' type='text'>
    <input type='submit'>
    </form>"
    ;

    $file=$_REQUEST['file'];
    if (!isset(
    $file)) {die("Please specify file name for download.");}

    function 
    find_file($fname
    {

      if (
    is_file('/downloads/'.$fname))
      {
        
    $file_path '/downloads/'.$fname ;
        return(
    $file_path);
      }
    }

    $fsize filesize($file_path);
      
    if (
    find_file($file))
    {
      
    header("Pragma: public");
      
    header("Expires: 0");
      
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      
    header("Cache-Control: public");
      
    header("Content-Description: File Transfer");
      
    header("Content-Disposition: attachment; filename=\"$file_path");
      
    header("Content-Transfer-Encoding: binary");
      
    header("Content-Length: ".$fsize);
    }else{
    echo 
    "That file does not exist. Please double-check your spelling.";
    }
    ?>

    </html>

  2. #2
    Join Date
    Aug 2007
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    May I suggest to keep the least Html into PHP.
    For example here:
    PHP Code:
    echo "<form method='post' action='download.php'>
    <input name='file' type='text'>
    <input type='submit'>
    </form>"

    It's just messy. keep it out of your php.

    Just to point it out.
    And what is the problem?(what the debugger says?)

  3. #3
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I know it's messy, but I'm just not sure how to make PHP forms.

    The script executes properly, so it's not an error, per se, just the script isn't working as I expected it to. The script doesn't find the files properly...I think there is something wrong with find_file.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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