PDA

Click to See Complete Forum and Search --> : Rewritting URLs


dclamp
Sep 30th, 2007, 05:12 PM
I am creating a videos page, and i need to display a video on the page, but i dont want to put the actual URL to the video. I want something like:

mysite/video.php?14323

and it will somehow rewrite the url in video.php to show the video... any thoughts on how to do this?

Fazi
Sep 30th, 2007, 07:14 PM
you mean, somthing like i have don here ?
http://youtubehits.freehostia.com/
:D

dclamp
Sep 30th, 2007, 09:59 PM
no. I need the video.php page to load the video

Fazi
Sep 30th, 2007, 11:44 PM
so dclam

You want to give the url like this

mysite/video.php?14323


I have given like this youtubehits.freehostia.com/index.php?topic=google_earth

what is the diffrent between us?

dclamp
Oct 1st, 2007, 04:26 PM
I think i explained wrong. I am embedding songs/videos on my website and i dont want the actual URL of the media to show, so i want to some how play it through another url.

Ex: here is the actual url of a file:
http://www.mysite.com/path/to/file.mp3

instead of showing that in my source, i want to show:
media.php?id=some_rand_hash

and in media.php, it does a mysql lookup, gets the actual url, and plays it... somehow.

I am going to try something with Headers...

Mad-Hatter
Oct 11th, 2007, 12:09 PM
<?php

$id = intval($_GET['fileid']);
// look up the file where id = $id
$file_path = get_file_path($id);
// perhaps set your mime-type here based on the file extension
// header("Content-type: audio/mpeg");
readfile($file_path);

?>

readfile (http://www.php.net/manual/en/function.readfile.php) will stream the file out for you, so http://yoursite/file.php?fileid=2 would return the file stream as if you requested it directly from the filesystem.

make sure you send the content-type in the header too. some browsers need this or else it won't display your youtube video, image, or mp3 file. you can base that off of you file extensions (ex: me.mp3 translates to "Content-type: audio/mpeg" and a png image would be "Content-type: image/png").