Results 1 to 8 of 8
  1. #1

    How to use a filename as a hyperlink

    HEY!
    I have in the Database where one field is the file name, i want to use that file name as a hyperlink , such that when you click on it, you should be able to download the file.
    <?php

    //capture search term and remove spaces at its both ends if the is any
    $searchTerm = trim($_GET['keyname']);

    //check whether the name parsed is empty
    if($searchTerm == "rinex_file")
    {
    echo "Enter name you are searching for.";
    exit();
    }

    //database connection info
    $host = "localhost"; //server
    $db = "r"; //database name
    $user = "m" //dabases user name
    $pwd = "c"; //password

    //connecting to server and creating link to database
    $link = mysqli_connect($host, $user, $pwd, $db);

    //MYSQL search statement
    $query = "SELECT * FROM rinexo WHERE rinex_file LIKE '%$searchTerm%'";

    $results = mysqli_query($link, $query);

    /* check whethere there were matching records in the table
    by counting the number of results returned */
    if(mysqli_num_rows($results) >= 1)
    {
    $output = "";
    while($row = mysqli_fetch_array($results))

    {
    $output .= "rinex version: " . $row['rinex_version'] . "<br />";

    $output .= "program: " . $row['pgm'] . "<br />";
    $output .= "date: " . $row['date'] . "<br />";
    $output .= "maker name: " . $row['marker_name'] . "<br />";
    $output .= "maker number: " . $row['marker_no'] . "<br />";
    $output .= "observer: " . $row['observer'] . "<br />";
    $output .= "agency: " . $row['agency'] . "<br />";
    $output .= "position_X_Y_Z: " . $row['position_X_Y_Z'] . "<br />";
    $output .= "delta: " . $row['delta'] . "<br />";
    $output .= "wavelength: " . $row['wavelength'] . "<br />";
    $output .= "rinex file: " . $row['rinex_file'] . "<br />";

    }
    echo $output;
    }
    else
    echo "There was no matching record for the name " . $searchTerm;
    ?>
    here the rinex_name is the one that needs to have an hyper link
    Last edited by madu; 09-23-2013 at 02:36 AM. Reason: needed to add more details

  2. #2
    Join Date
    Apr 2003
    Location
    Atlanta, Jawja
    Posts
    3,074
    Is the file stored in the database (bad idea, if it is) or stored as an actual file on the server itself? The answer to this determines how we answer.
    Doug Hazard - "retired" Web Hosting Master
    * Full Stack (Web/WP) Dev for The Catholic Diocese of Richmond (160+ sites)
    * Sports Photographer, Media Personality and CFB Historian
    * Tech Admin for several Sports Networks/Sites

  3. #3
    HEY!
    yeah the file is stored in the database( a directory) as of now, after which it will be deployed on to a server, i need to be able to use the file as a hyperlink so that one can download it on to thier systems.

  4. #4
    Join Date
    Apr 2003
    Location
    Atlanta, Jawja
    Posts
    3,074
    You might want to re-think doing that. One of the best decisions I ever made was to stop storing files in the database. You can still mask their location via PHP and MySQL, but you need to consider not utilizing database stored files.

    That being said, there's a pretty basic tutorial for downloading the files that you have stored. You need to learn about "MIME types".

    Have a peek at http://php.about.com/od/phpbasics/ss/mysql_files_6.htm (again, VERY basic, but should give you a good starting point)
    Doug Hazard - "retired" Web Hosting Master
    * Full Stack (Web/WP) Dev for The Catholic Diocese of Richmond (160+ sites)
    * Sports Photographer, Media Personality and CFB Historian
    * Tech Admin for several Sports Networks/Sites

  5. #5
    This really nice post. keep on posting this kind of helpful posts. thumbs up

  6. #6
    hey!
    the link that u sent is very good! but doesnt serve my purpose, here is what i really want. on the template i want a hyperlink to the file abc.03h , when i click on this i should be able to download this on the system. how do i get the file names from the server on the template for me to choose to click to download?

  7. #7
    Join Date
    Apr 2003
    Location
    Atlanta, Jawja
    Posts
    3,074
    madu, the link I provided actually covers EXACTLY what you need. You could also google "Doownload binary file stored in mysql"
    Doug Hazard - "retired" Web Hosting Master
    * Full Stack (Web/WP) Dev for The Catholic Diocese of Richmond (160+ sites)
    * Sports Photographer, Media Personality and CFB Historian
    * Tech Admin for several Sports Networks/Sites

  8. #8
    http://www.computerhope.com/issues/ch001113.htm i need to implement this concept!

Similar Threads

  1. Hyperlink help!
    By dannym031292 in forum Web Design and Content
    Replies: 2
    Last Post: 12-30-2007, 04:38 PM
  2. Hyperlink Problem
    By Melamorie in forum Hosting Security and Technology
    Replies: 2
    Last Post: 04-18-2007, 10:30 PM
  3. simple hyperlink help
    By hoachen in forum Programming Discussion
    Replies: 8
    Last Post: 08-11-2005, 06:44 PM
  4. POST w/ HYPERLINK
    By tylerg in forum Programming Discussion
    Replies: 5
    Last Post: 07-21-2004, 02:28 PM
  5. Signature Hyperlink
    By HostBidder in forum WHT Announcements, Feedback and Questions
    Replies: 6
    Last Post: 03-18-2004, 10:31 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
  •