Help to create id for files!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help to create id for files!

    How can we create id for files like 'example.com/download.php?id=1254'
    ?
    please help me friends!?

    #2
    You will have to put records in a database or flatfile etc

    A simple way to do that

    Imagine u've got a table in a database with 3 coloums

    ID | fileName | URL
    -------------------------------------------------
    1 | flower.jpg | /files/images/flower.jpg
    2 | music.mp3| /files/music/music.mp3
    3 | vido.mp4 | /files/videos/vido.mp4
    -------------------------------------------------

    Then make a custom php script ~ download.php

    PHP Code:
    <?
    if (isset($_GET['ID']))
    {
     
    mysql_connect("localhost", "root", "");
    mysql_select_db("DATABASE");
       $ID = (int) $_GET['ID'];
       $sql = "SELECT URL FROM TABLE_NAME WHERE ID = $ID LIMIT 1";
       $result = mysql_query($sql);
       if (mysql_num_rows($result) == 1)
       {
               $row = mysql_fetch_assoc($result);
               //Redirect user to the file
               $download_url = "http://example.com".$row['URL'];
               header("Location: $download_url");
               exit();
       }
       else
       {
               echo "Not found!";
       }
    }
    ?>
    There are many more ways to do the same thing, its up to your creativity
    Last edited by softwarefreak; 08.08.12, 10:08.
    I need some facebook likes, can you please help me
    http://facebook.com/softwarefreakin
    I noticed social media is really powerful
    Well DONE is better than well SAID

    Comment


      #3
      Originally posted by softwarefreak View Post
      You will have to put records in a database or flatfile etc

      A simple way to do that

      Imagine u've got a table in a database with 3 coloums

      ID | fileName | URL
      -------------------------------------------------
      1 | flower.jpg | /files/images/flower.jpg
      2 | music.mp3| /files/music/music.mp3
      3 | vido.mp4 | /files/videos/vido.mp4
      -------------------------------------------------

      Then make a custom php script ~ download.php

      PHP Code:
      <?
      if (isset($_GET['ID']))
      {
       
      mysql_connect("localhost", "root", "");
      mysql_select_db("DATABASE");
         $ID = (int) $_GET['ID'];
         $sql = "SELECT URL FROM TABLE_NAME WHERE ID = $ID LIMIT 1";
         $result = mysql_query($sql);
         if (mysql_num_rows($result) == 1)
         {
                 $row = mysql_fetch_assoc($result);
                 //Redirect user to the file
                 $download_url = "http://example.com".$row['URL'];
                 header("Location: $download_url");
                 exit();
         }
         else
         {
                 echo "Not found!";
         }
      }
      ?>
      There are many more ways to do the same thing, its up to your creativity
      Thanks bro for your support!
      can we use arrays instead of sql?
      Last edited by TRUEWAP; 08.08.12, 11:00.

      Comment

      Working...
      X