Help to create id for files!

Started on the old forum in August 2012 · view the original in the archive · old links redirect here

2 replies · 444 views · started 14 years ago · 1 min read

2 participants
TRUEWAP Newbie · 6 posts #1

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

softwarefreak Senior · 349 posts #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

<?
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

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

TRUEWAP Newbie · 6 posts #3

softwarefreak wrote: 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

<?
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?

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close