question about $_GET['$ID'] in download.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
janlux
Forum Newbie
Posts: 4
Joined: Fri Aug 28, 2009 2:22 pm

question about $_GET['$ID'] in download.php

Post by janlux »

Hi all,

At the first, my congratulations for the forum, its seems that is a lot of info here :drunk:

Here is my question on $_GET['$ID'] im new on this :banghead: ...so if some one can help me it will be great! :oops:


I have a few files (mp3) in my web site, that I want the users download them from download.php from id

there are few files in my web site mp3

for ejemple to download the file 93856.mp3 and 49673.mp3 depending on url id in download.php Im about what to put...i have something like this...


<?php

$id=$_GET['id_song'];


$ID = $_GET['id'];
switch ('ID') {
case 1:
$ann = '93856';
$atr = '.mp3';
case 2:
$ann = '49673';
$atr = '.mp3';
$id_song=
?>

or is something like this?

<?php
$id=$_GET['id_song'];

$id_song=93856
$id_song=49673
?>

to get download the files the url for this files is ejemple:

http://www.mywebsite.com/folder/downloa ... song=93856

http://www.mywebsite.com/folder/downloa ... song=49673

or this is wrong? cos' I've read some article on this...but its seems is wrong in all....

help me please... :roll:


hugs to all :wink:
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: question about $_GET['$ID'] in download.php

Post by cpetercarter »

The simple thing is a link which points directly at the file your listeners want to download eg http://www.mysite.com/audio/12345.mp3.

The alternative is some sort of indirect link. For example, http://www.mysite.com/getaudio.php?id=12345. The script 'getaudio.php' would take the value of $_GET['id'] and create a direct link to the required file. A very simple example might be:

Code: Select all

 
//make the filename from the id
$requested_file = $_GET['id']."mp3";
 
//then construct the url of the requested file
$requested_url = "http://www.mysite.com/audio/".$requested_file;
 
//then redirect to the correct location
header("Location: ".$requested_url, FALSE, 302);
 
janlux
Forum Newbie
Posts: 4
Joined: Fri Aug 28, 2009 2:22 pm

Re: question about $_GET['$ID'] in download.php

Post by janlux »

Hello cpetercarter,

Thank you a lot for this !

If I understand and I want the alternative the indirect link, as I have 5 songs the code will be something like this isnt?:
the folder where I have the songs is called audio.


the name of file php : getaudio.php

Code: Select all

<?php
 
//make the filename from the id
$requested_file = $_GET['id']."mp3";
 
//then construct the url of the requested file
$requested_url = "http://www.mysite.com/audio/".$requested_file;
 
//then redirect to the correct location
header("Location: ".$requested_url, FALSE, 302);
 
?>
did I need to put the name of the song in the "Location: " ? or the code that you give me is ok and no need to be modificatE?

Because I need that the peopel can save it in theyr PC, any idea on this?

And a lot of thank you!!

Hugs!
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: question about $_GET['$ID'] in download.php

Post by mrvijayakumar »

Hi,

Use downloading script to download the file from web sites. It will be nice for downloading.

viewtopic.php?f=1&t=104572
janlux
Forum Newbie
Posts: 4
Joined: Fri Aug 28, 2009 2:22 pm

Re: question about $_GET['$ID'] in download.php

Post by janlux »

Hi mrvijayakumar, thanks for the help, but I didnt undestand it very well.....im newby in php ...

I only want that the people can save the file when they get to the next url:

http://www.mysite.com/getaudio.php?id=12345. with no streaming...only save as and they can save it into their computer....

My code in download is:

<?php

//make the filename from the id
$requested_file = $_GET['id']."mp3";

//then construct the url of the requested file
$requested_url = "http://www.mysite.com/audio/".$requested_file;

//then redirect to the correct location
header("Location: ".$requested_url, FALSE, 302);

?>


works very good, but I need only one thing, that permit to ''save as'' the file.......any idea? :(
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: question about $_GET['$ID'] in download.php

Post by Ollie Saunders »

header('Content-Disposition: attachment') or something like that.
janlux
Forum Newbie
Posts: 4
Joined: Fri Aug 28, 2009 2:22 pm

Re: question about $_GET['$ID'] in download.php

Post by janlux »

Ok thank you all :) finally I make it! :)
Post Reply