Problem sa skriptom za prikaz i download mp3 fajlova

Problem sa skriptom za prikaz i download mp3 fajlova

offline
  • Pridružio: 08 Nov 2007
  • Poruke: 12
  • Gde živiš: Brcko, BiH

Imam problem sa ovom skriptom koju sam skinuo sa neta.
Dao sam joj naziv muzika.php

<?php /* * The function of this script, is to distinguish wether the returned array is a file or directory, * if it is a file, it generates a link to download the file, otherwise if it's a dir, * it creates a link to list the files/dirs in that directory, works on windows and *nix platforms. * * v0.1: - initial release * v0.2: - small fix for null directory * v0.3: - small security fix * v0.4: - changed some stuff * v0.5: - security fix, update * * licence: gnu * -- ds@breed.co.za */ /* config for the script */ define("DOWNLOAD_PATH", "muzika"); /* path to your files, NB: no slash at the end */ /* start the script... no more editing from here on needed... */ /* get a list of the files + dirs and turn the list into an array */ function file_list($dir) {   if (is_dir($dir)) {     $fd = @opendir($dir);     while (($part = @readdir($fd)) == true) {       clearstatcache();       if ($part != "." && $part != "..") {         $file_array[] = $part;       }     }     if ($fd == true) {       closedir($fd);     }     if (is_array($file_array)) {       natsort($file_array);       return $file_array;     } else {       return false;     }   } else {     return false;   } } /* function to convert to Mb, Kb and bytes */ function file_size($size) {   if ($size > 1048576) { /* literal.float */     return $re_sized = sprintf("%01.2f", $size / 1048576) . " Mb";   } elseif ($size > 1024) {     return $re_sized = sprintf("%01.2f", $size / 1024) . " Kb";   } else {     return $re_sized = $size . " bytes";   } } /* prevent people from trying to view directories up */ function strip_junk($str) {   return trim(str_replace("//", "/", str_replace("..", "", stripslashes(urldecode($str))))); } /* get a list of the files/dirs, put them into a table. */ function generate_file_list($path) {   $final_path = strip_junk($path);   $file_array = file_list(DOWNLOAD_PATH . "/$final_path/");   echo "<b>$final_path/</b>\n";   echo "<br><br>\n\n";   if ($file_array == false) { /* check if the dir is an array before we process it to foreach(); */     echo "Folder je prazan\n";   } else {     echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";     echo "<tr><td><b>Naziv</b></td><td><b>Velicina</b></td></tr>n";     foreach ($file_array as $file_name) {       $is_file = DOWNLOAD_PATH . "/$final_path/$file_name";       $file_size = file_size(filesize(DOWNLOAD_PATH . "/$final_path/$file_name"));       if (is_file($is_file)) {         print "<tr><td><a href=\"" .  $_SERVER["PHP_SELF"] . "?go=download&path=" . urlencode($final_path) . "&file=" . urlencode($file_name) . "\">$file_name</a></td><td>" . $file_size . "</td></tr>\n";       } elseif (is_dir($is_file)) {         print "<tr><td><a href=\"" . $_SERVER["PHP_SELF"] . "?go=list&path=" . urlencode($final_path) . "/" . urlencode($file_name) . "\">$file_name/</a></td><td>&lt;dir&gt;</td></tr>n"; /* we don't need a size for a directory */       }     }     echo "</table>\n";   } } /* allow the user to download the file... */ function do_download($path, $file) {   $get_path = strip_junk($path);   $get_file = strip_junk($file); /* fopen adds  to ' - so we strip 'em. */   header("Content-Disposition: atachment; filename=" . $get_file);   header("Content-Type: application/octet-stream");   header("Content-Length: " . filesize(DOWNLOAD_PATH . "/$get_path/$get_file"));   header("Cache-Control: no-cache, must-revalidate");   header("Pragma: no-cache");   header("Expires: 0");   $fp = fopen(DOWNLOAD_PATH . "/$get_path/$get_file", "r");   print fread($fp, filesize(DOWNLOAD_PATH . "/$get_path/$get_file"));   fclose($fp);   exit; } if (!isset($_GET[go]) || $_GET[go] == "dirlist") {   generate_file_list(""); /* null, so we get a list for the root directory */ } elseif ($_GET[go] == "list" && isset($_GET[path])) {   if (isset($_GET[path])) { /* if the path is null - it returns a list for the root directory */     generate_file_list($_GET[path]); /* get a list for the path specified */   } else {     generate_file_list("");   } } elseif ($_GET[go] == "download") {   if (isset($_GET[path]) && isset($_GET[file])) {     do_download($_GET[path], $_GET[file]); /* download the file... */   } else {     echo "nije izabran fajl za download :)\n";   } } ?>

Kada pozovem muzika.php kao samostalni fajl dobro mi ucita sve pjesme iz foldera muzika, tako da ih mogu skinuti sa servera. Medjutim, kada hocu ovaj fajl da pozovem funkcijom include sa neke druge stranice, pojave mi se sve pjesme u listi kao sto i treba, ali kada kliknem na neku od pjesama da bih je skinuo otvori mi ponovo stranicu i ispise samo tekst, kao kada bi otvorili pjesmu koja je u mp3 formatu u notepad-u.



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 715 korisnika na forumu :: 38 registrovanih, 3 sakrivenih i 674 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: A.R.Chafee.Jr., Arsenije, awathorn, bbogdan, Bobrock1, Bubimir, darkstar101, ddjxxi, Dorcolac, Drug pukovnik, Georgius, goran.vvv, goxin, HrcAk47, hyla, indja, JOntra, lelemud, LonelyWolf, maiden6657, MB120mm, mb1213, Mixelotti, mnn2, nemkea71, raptorsi, raskoljnikov, Ripanjac, sickmouse, Srle993, stagezin, Toni, VladaKG1980, VojvodaMisic, vukovi, W123, Šraf, Žukov