Forum Moderators: coopster
say you have a url like ..download.php?file=file.mp3
in download.php, using $file = $_GET['file'] would be way to dangerous......
how do YOU tackle the directory traversal issue? (?file=../../etc/passwd)
So, basically you have a list of valid files first, then compare the requested filename to the files in the directory. You will never get a match on '../../etc/passwd' so you would throw your error.
$file = $_GET['song'];
if (!empty($file)){
$file = str_replace('../', '', $file);
}
a little more help is required though
I have a script on one page which reads a dir and randomly selects a file from the dir and returns the filename
I have an embedded mediaplayer on the same page, like this:
[/www.url.com/binaries/play.php?song=<?...] echo htmlspecialchars($music_arr[$rand_song]);?>
In the play.php script I store the songname in a variable, change the directory to the directory the file is really in (not binaries) and use fopen() to access the file
even though this is all working (fopen() is succesful), the song does not start to play?
I expected it to, but obviously there's an error in my thinking here.
any ideas?