crazyjust Posted November 27, 2009 Share Posted November 27, 2009 I'm sorry. i'm not a coder. I have this script for forcing download and previewing mp3. The guy that coded it made it so It took the spaces out of the filename when its downloaded. When you download a file, it downloads as Artist-SongTitle.mp3 instead of Artist - Song Title.mp3 Could someone please tell me how I would be able to correct this, or if its even possible? <?php require_once("config.php"); require_once("connect.php"); require_once("class2.php"); define("e_PAGETITLE", "Music"); require_once(HEADERF); if (!USER) { $ns->tablerender("Error!", "You must login to view this page"); require_once(FOOTERF); exit; } session_start(); if(isset($_GET['search'])){ $_SESSION['music-dl-page'] = 0; $_GET['search']=mysql_real_escape_string($_GET['search']); } if(!isset($_SESSION['music-dl-page'])){ $_SESSION['music-dl-page'] = 0; } if(isset($_GET['p'])){ $_SESSION['music-dl-page'] = (int)mysql_real_escape_string($_GET['p']); } ?> <?php function mksize($bytes) { if ($bytes < 1000 * 1024) return number_format($bytes / 1024, 2) . " kB"; elseif ($bytes < 1000 * 1048576) return number_format($bytes / 1048576, 2) . " MB"; elseif ($bytes < 1000 * 1073741824) return number_format($bytes / 1073741824, 2) . " GB"; else return number_format($bytes / 1099511627776, 2) . " TB"; } function getico($type) { switch(strtolower($type)) { case "mp3": return "mp3.gif"; break; case "exe": case "setup": case "msi": return "exe.gif"; break; case "zip": return "zip.gif"; break; case "rar": case "bin": case "tar": case "bz2": case "gz": case "z": case "7z": case "s7z": return "rar.gif"; break; case "mpg": case "mp4": case "mpeg": return "mp4.gif"; break; case "avi": return "avi.gif"; break; case "iso": case "img": case "cue": return "iso.gif"; break; case "vob": return "vob.gif"; break; default: return "unknown.gif"; break; } } $filedirxtra= (isset($_GET['dir']) ? htmlspecialchars($_GET['dir'])."/" : ""); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Music Downloads</title> <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" /> <script type="text/javascript" src="/silverlight.js"></script> <script type="text/javascript" src="/wmvplayer.js"></script> <script type="text/javascript" src="/new_player_script.js"></script> <style type="text/css"> #player-bar {position:relative;cursor:default;} #fplayer {position:relative;width:320px;overflow:hidden;} #marquee {position:relative;overflow:hidden;cursor:default;color:#fff;} </style> <style type="text/css"> body { font-family: Verdana, Tahoma, Helvetica, Arial; font-size: 10pt; } table.list tr td { border-bottom: 1px solid orange; } a { text-decoration: none; } a:hover { text-decoration: underline; } #txtsrch { background-image: url("icons/srchico.png"); background-position: left center; background-repeat: no-repeat; background-color: #cccccc; font-weight: bold; font-size: 11pt; padding-left: 25px; height: 20px; } #srchbtn { background: transparent; background-image: url("dl-icons/srchbtn.gif"); background-position: center center; background-repeat: no-repeat; height: 25px; width: 70px; border: none; } </style> <script type="text/javascript"> function preview(file) { var f = document.getElementById('fplayer'); document.getElementById('player-box').style.display='block'; f.innerHTML= '<object type="application/x-shockwave-flash" data="rawr_player.swf" width="320" height="50">'+ '<param name="movie" value="http://rawr-designs.com/rawr_data/players/rawr_player.swf"/>'+ '<param name="bgcolor" value="#741e1f"/>'+ '<param name="wmode" value="transparent"/>'+ '<param id="flashvars" name="flashvars" value="autoplay=on&colorset=rawr_red&context=off&file='+file+'" />'+ '</object>'; } </script> <script src="javascripts/prototype.js" type="text/javascript"></script> <script src="javascripts/scriptaculous.js" type="text/javascript"></script> </head> <body> <div align="center"><b><font size="2"><font color="#FFAD5B">You Can Upload Music <a href="/fileupload.php" title="Music Upload">Here</a></font></b> </div> <!--Nav--> <div style="padding: 5px; margin: 10px; width: auto; height: 30px; border: 1px solid orange;"> <!-- Table hack required for IE--> <table cellpadding="0" cellspacing="0" border="0" width="auto" style="border: none;"> <tr> <td valign="middle" align="left"> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php if ($filedirxtra != "") echo "<input type='hidden' name='dir' value='".$filedirxtra."' />"; ?> <input id="txtsrch" type="text" size="25" name="search" /> <input id="srchbtn" type="submit" value=" " /> </form> </table> </div> <html> <body> <?php $sql = "SELECT COUNT(*) FROM cust_music_files".$kw; $result = mysql_query( $sql, $conn ) or die(mysql_error()); $row = mysql_fetch_array($result); echo $row[0]; ?> </font></font></b> <b><font size="3"><font color="#FFAD5B">Songs In Our Database</font></font></b></p> <p><iframe src="previewplr/previewthis.php" width="500" height="50" id="playmusic" name="playmusic" frameborder="no" marginwidth="0" marginheight="0" scrolling="no"></iframe></p> </div> <br /> <br /> </body> </html> <?php $kw = (isset($_GET['search']) ? " WHERE filename LIKE '%".trim($_GET['search'])."%'" : ""); $sql = "SELECT COUNT(*) FROM cust_music_files".$kw; $result = mysql_query( $sql, $conn ) or die(mysql_error()); $row = mysql_fetch_array($result); echo '<a href="?p=0&search='.$_GET['search'].'"><<</a> '; for($i=max(0,$_SESSION['music-dl-page']-5);$i<min($row[0]/25,$_SESSION['music-dl-page']+5);$i++){ if($i==$_SESSION['music-dl-page']){ echo $i.' '; }else{ echo '<a href="?p='.$i.'&search='.$_GET['search'].'">'.$i.'</a> '; } } echo '<a href="?p='.(floor(($row[0]-1)/25)).'&search='.$_GET['search'].'">>></a> '; ?> <div id="player-box" style="/*height: 75px;*/ background-color: #880000; display: none; position: fixed; top: 150px; left: 200px;border: 2px solid #440000; width: auto; margin: 0px; text-align: right;"> <div id="player-bar" style="font-family: sans-serif; font-style: normal; font-weight: bold; font-size: 20px; height: 25px; width: 320px; font: ; background-color: #880000; text-align: right;"><a href="#" onclick="javascript: document.getElementById('player-box').style.display='none';document.getElementById('fplayer').innerHTML='';return false;" style="color: white;">X</a> </div> <div id="fplayer"></div> <script type="text/javascript"> var elm3 = document.getElementById("fplayer"); var src = '/wmvplayer.xaml'; var cfg = { file:'', width:'320', height:'20', autostart:'false', volume:'50', frontcolor:'ffffff', backcolor:'880000', lightcolor:'e9e9e9' }; var ply = new jeroenwijering.Player(elm3,src,cfg); </script> <div id="marquee"> </div> </div> <script language="javascript"><!-- function popupWindow(url) { var centerWidth = (window.screen.width - 400) / 2; var centerHeight = (window.screen.height - 400) / 2; window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=150,height=60,screenX=150,screenY=150,top=' + centerHeight + ',left='+centerWidth); } //--></script> <table class="list" width="auto" cellpadding="3" cellspacing="0" border="0" style="margin: auto; border: 1px solid orange;"> <?php $sql = "SELECT * FROM cust_music_files".$kw." ORDER BY filename LIMIT ".($_SESSION['music-dl-page']*25).", 25"; $result = mysql_query( $sql, $conn ) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $file=stripslashes($row['filename']); $filedirxtra=substr($row['filename'],0,1).'/'; $fext = explode(".", $file); print("<tr><td><img src='".$icondir.getico(end($fext))."' title='".end($fext)."' alt='".end($fext)."' border='0'/></td><td width='auto'>".htmlspecialchars($file)."</td><td><span style='white-space: nowrap;'> ".mksize(filesize($filedir.$filedirxtra.$file))."</span></td><td><a href=\"downmusic.php?link=".htmlspecialchars($filedir.$filedirxtra.$file)."\"><img src='".$icondir."download.gif' border='0' alt='DL' title='Download File: ".htmlspecialchars($file)."' /></a></td><td>".(in_array(end($fext), $prvfiles) ? "<a href=\"previewplr/previewthis.php?link=".htmlspecialchars(addslashes($filedir.$filedirxtra.$file))."\" target='playmusic'><img src='".$icondir."preview.gif' border='0' alt='Preview' title='Preview File: ".htmlspecialchars($file)."' /></a>" : " ")."</td></tr>"); } ?> </table> </div> <script type="text/javascript" language="javascript"> // <![CDATA[ new Draggable("player-box", {starteffect: null, endeffect: null}); // ]]> </script> <?php require_once(FOOTERF); exit; ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/ Share on other sites More sharing options...
oni-kun Posted November 27, 2009 Share Posted November 27, 2009 I'm afraid in that exact code there is nothing about taking out the spaces from the title of the mp3. Browse the code elsewhere for something along the lines of 'fopen()' function where it actually uploads the file, it should show REGEX or str_replace() where it filters the name. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966212 Share on other sites More sharing options...
crazyjust Posted November 27, 2009 Author Share Posted November 27, 2009 How about this code? <?php // force to download a file $file = str_replace("\'","'",stripslashes($_GET['link']));//"http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3"; $filename = str_replace(" ","",$file); $filename = substr($filename,strrpos($filename,"/")+1); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".$filename); header( "Content-Description: File Transfer"); @readfile($file); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966214 Share on other sites More sharing options...
razta Posted November 27, 2009 Share Posted November 27, 2009 Try commenting out: $filename = str_replace(" ","",$file); So it should look: // $filename = str_replace(" ","",$file); See if that works. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966230 Share on other sites More sharing options...
crazyjust Posted November 27, 2009 Author Share Posted November 27, 2009 I tried that like you said but it didnt work. I only tested in ie, but all it did was open up a blank white new window. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966241 Share on other sites More sharing options...
premiso Posted November 27, 2009 Share Posted November 27, 2009 I tried that like you said but it didnt work. I only tested in ie, but all it did was open up a blank white new window. If the spaces are being removed when uploaded then ya, commenting out that line will not work. Instead add this in there: <?php // force to download a file $file = str_replace("\'","'",stripslashes($_GET['link']));//"http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3"; $filename = str_replace("-"," - ",$file); $filename = substr($filename,strrpos($filename,"/")+1); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".$filename); header( "Content-Description: File Transfer"); @readfile($file); ?> And see if that works for you, unsure if it will but it should. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966262 Share on other sites More sharing options...
crazyjust Posted November 27, 2009 Author Share Posted November 27, 2009 That didn't work. It brought up a blank white page also. Here is my music.php Not sure if it will tell anything. <?php require_once("config.php"); require_once("connect.php"); require_once("class2.php"); define("e_PAGETITLE", "Music"); require_once(HEADERF); if (!USER) { $ns->tablerender("Error!", "You must login to view this page"); require_once(FOOTERF); exit; } session_start(); if(isset($_GET['search'])){ $_SESSION['music-dl-page'] = 0; $_GET['search']=mysql_real_escape_string($_GET['search']); } if(!isset($_SESSION['music-dl-page'])){ $_SESSION['music-dl-page'] = 0; } if(isset($_GET['p'])){ $_SESSION['music-dl-page'] = (int)mysql_real_escape_string($_GET['p']); } ?> <?php function mksize($bytes) { if ($bytes < 1000 * 1024) return number_format($bytes / 1024, 2) . " kB"; elseif ($bytes < 1000 * 1048576) return number_format($bytes / 1048576, 2) . " MB"; elseif ($bytes < 1000 * 1073741824) return number_format($bytes / 1073741824, 2) . " GB"; else return number_format($bytes / 1099511627776, 2) . " TB"; } function getico($type) { switch(strtolower($type)) { case "mp3": return "mp3.gif"; break; case "exe": case "setup": case "msi": return "exe.gif"; break; case "zip": return "zip.gif"; break; case "rar": case "bin": case "tar": case "bz2": case "gz": case "z": case "7z": case "s7z": return "rar.gif"; break; case "mpg": case "mp4": case "mpeg": return "mp4.gif"; break; case "avi": return "avi.gif"; break; case "iso": case "img": case "cue": return "iso.gif"; break; case "vob": return "vob.gif"; break; default: return "unknown.gif"; break; } } $filedirxtra= (isset($_GET['dir']) ? htmlspecialchars($_GET['dir'])."/" : ""); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Music Downloads</title> <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" /> <script type="text/javascript" src="/silverlight.js"></script> <script type="text/javascript" src="/wmvplayer.js"></script> <script type="text/javascript" src="/new_player_script.js"></script> <style type="text/css"> #player-bar {position:relative;cursor:default;} #fplayer {position:relative;width:320px;overflow:hidden;} #marquee {position:relative;overflow:hidden;cursor:default;color:#fff;} </style> <style type="text/css"> body { font-family: Verdana, Tahoma, Helvetica, Arial; font-size: 10pt; } table.list tr td { border-bottom: 1px solid orange; } a { text-decoration: none; } a:hover { text-decoration: underline; } #txtsrch { background-image: url("icons/srchico.png"); background-position: left center; background-repeat: no-repeat; background-color: #cccccc; font-weight: bold; font-size: 11pt; padding-left: 25px; height: 20px; } #srchbtn { background: transparent; background-image: url("dl-icons/srchbtn.gif"); background-position: center center; background-repeat: no-repeat; height: 25px; width: 70px; border: none; } </style> <script type="text/javascript"> function preview(file) { var f = document.getElementById('fplayer'); document.getElementById('player-box').style.display='block'; f.innerHTML= '<object type="application/x-shockwave-flash" data="rawr_player.swf" width="320" height="50">'+ '<param name="movie" value="http://rawr-designs.com/rawr_data/players/rawr_player.swf"/>'+ '<param name="bgcolor" value="#741e1f"/>'+ '<param name="wmode" value="transparent"/>'+ '<param id="flashvars" name="flashvars" value="autoplay=on&colorset=rawr_red&context=off&file='+file+'" />'+ '</object>'; } </script> <script src="javascripts/prototype.js" type="text/javascript"></script> <script src="javascripts/scriptaculous.js" type="text/javascript"></script> </head> <body> <div align="center"><b><font size="2"><font color="#FFAD5B">You Can Upload Music <a href="/fileupload.php" title="Music Upload">Here</a></font></b> </div> <!--Nav--> <div style="padding: 5px; margin: 10px; width: auto; height: 30px; border: 1px solid orange;"> <!-- Table hack required for IE--> <table cellpadding="0" cellspacing="0" border="0" width="auto" style="border: none;"> <tr> <td valign="middle" align="left"> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php if ($filedirxtra != "") echo "<input type='hidden' name='dir' value='".$filedirxtra."' />"; ?> <input id="txtsrch" type="text" size="25" name="search" /> <input id="srchbtn" type="submit" value=" " /> </form> </table> </div> <html> <body> <br /><div align="center"> <p><b><font color="#FFAD5B"><font size="2">This Is All The Music I Gathered Over The Years <br /> Some I Downloaded, And Some Have Been Uploaded <br /> All These Files Have Been Scanned With AVG Professional Anti Virus</font></font></b> <br /> <br /> <b><font color="#FFAD5B"><font size="3">There Are Currently </font></font></b> <b><font size="4"><font color="#FF0000"> <?php $sql = "SELECT COUNT(*) FROM cust_music_files".$kw; $result = mysql_query( $sql, $conn ) or die(mysql_error()); $row = mysql_fetch_array($result); echo $row[0]; ?> </font></font></b> <b><font size="3"><font color="#FFAD5B">Songs In Our Database</font></font></b></p> <p><iframe src="previewplr/previewthis.php" width="500" height="50" id="playmusic" name="playmusic" frameborder="no" marginwidth="0" marginheight="0" scrolling="no"></iframe></p> </div> <br /> <br /> </body> </html> <?php $kw = (isset($_GET['search']) ? " WHERE filename LIKE '%".trim($_GET['search'])."%'" : ""); $sql = "SELECT COUNT(*) FROM cust_music_files".$kw; $result = mysql_query( $sql, $conn ) or die(mysql_error()); $row = mysql_fetch_array($result); echo '<a href="?p=0&search='.$_GET['search'].'"><<</a> '; for($i=max(0,$_SESSION['music-dl-page']-5);$i<min($row[0]/25,$_SESSION['music-dl-page']+5);$i++){ if($i==$_SESSION['music-dl-page']){ echo $i.' '; }else{ echo '<a href="?p='.$i.'&search='.$_GET['search'].'">'.$i.'</a> '; } } echo '<a href="?p='.(floor(($row[0]-1)/25)).'&search='.$_GET['search'].'">>></a> '; ?> <div id="player-box" style="/*height: 75px;*/ background-color: #880000; display: none; position: fixed; top: 150px; left: 200px;border: 2px solid #440000; width: auto; margin: 0px; text-align: right;"> <div id="player-bar" style="font-family: sans-serif; font-style: normal; font-weight: bold; font-size: 20px; height: 25px; width: 320px; font: ; background-color: #880000; text-align: right;"><a href="#" onclick="javascript: document.getElementById('player-box').style.display='none';document.getElementById('fplayer').innerHTML='';return false;" style="color: white;">X</a> </div> <div id="fplayer"></div> <script type="text/javascript"> var elm3 = document.getElementById("fplayer"); var src = '/wmvplayer.xaml'; var cfg = { file:'', width:'320', height:'20', autostart:'false', volume:'50', frontcolor:'ffffff', backcolor:'880000', lightcolor:'e9e9e9' }; var ply = new jeroenwijering.Player(elm3,src,cfg); </script> <div id="marquee"> </div> </div> <script language="javascript"><!-- function popupWindow(url) { var centerWidth = (window.screen.width - 400) / 2; var centerHeight = (window.screen.height - 400) / 2; window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=150,height=60,screenX=150,screenY=150,top=' + centerHeight + ',left='+centerWidth); } //--></script> <table class="list" width="auto" cellpadding="3" cellspacing="0" border="0" style="margin: auto; border: 1px solid orange;"> <?php $sql = "SELECT * FROM cust_music_files".$kw." ORDER BY filename LIMIT ".($_SESSION['music-dl-page']*25).", 25"; $result = mysql_query( $sql, $conn ) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $file=stripslashes($row['filename']); $filedirxtra=substr($row['filename'],0,1).'/'; $fext = explode(".", $file); print("<tr><td><img src='".$icondir.getico(end($fext))."' title='".end($fext)."' alt='".end($fext)."' border='0'/></td><td width='auto'>".htmlspecialchars($file)."</td><td><span style='white-space: nowrap;'> ".mksize(filesize($filedir.$filedirxtra.$file))."</span></td><td><a href=\"downmusic.php?link=".htmlspecialchars($filedir.$filedirxtra.$file)."\"><img src='".$icondir."download.gif' border='0' alt='DL' title='Download File: ".htmlspecialchars($file)."' /></a></td><td>".(in_array(end($fext), $prvfiles) ? "<a href=\"previewplr/previewthis.php?link=".htmlspecialchars(addslashes($filedir.$filedirxtra.$file))."\" target='playmusic'><img src='".$icondir."preview.gif' border='0' alt='Preview' title='Preview File: ".htmlspecialchars($file)."' /></a>" : " ")."</td></tr>"); } ?> </table> </div> <script type="text/javascript" language="javascript"> // <![CDATA[ new Draggable("player-box", {starteffect: null, endeffect: null}); // ]]> </script> <?php require_once(FOOTERF); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966366 Share on other sites More sharing options...
Zane Posted November 27, 2009 Share Posted November 27, 2009 your coder most likely removed the spaces for a reason. Seeing as how spaces can ultimately make a filename .... not work.. I'd say that was why. If you really want them back I would replace them with something.... Browser friendly... because spaces definitely aren't. Try commenting out: $filename = str_replace(" ","",$file); So it should look: // $filename = str_replace(" ","",$file); So as for commenting that line out... or changing it to the dash.. Don't. Try this and see what happens $filename = str_replace(" ","%20",$file); Why %20 Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966383 Share on other sites More sharing options...
crazyjust Posted November 27, 2009 Author Share Posted November 27, 2009 So as for commenting that line out... or changing it to the dash.. Don't. Try this and see what happens $filename = str_replace(" ","%20",$file); Why %20 Thank you for that That makes it download like this Artist%20-%20Song%20Title.mp3 I would like it like this Artist - Song Title.mp3 I guess its not possible Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966665 Share on other sites More sharing options...
mrMarcus Posted November 27, 2009 Share Posted November 27, 2009 try this: <?php // force to download a file $file = str_replace("\'","'",stripslashes($_GET['link']));//"http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3"; $filename = str_replace("-"," - ",$file); $filename = substr($filename,strrpos($filename,"/")+1); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\""); header("Content-Description: File Transfer"); @readfile($file); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966683 Share on other sites More sharing options...
crazyjust Posted November 28, 2009 Author Share Posted November 28, 2009 try this: <?php // force to download a file $file = str_replace("\'","'",stripslashes($_GET['link']));//"http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3"; $filename = str_replace("-"," - ",$file); $filename = substr($filename,strrpos($filename,"/")+1); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\""); header("Content-Description: File Transfer"); @readfile($file); ?> That shows the code in a white page Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966723 Share on other sites More sharing options...
oni-kun Posted November 28, 2009 Share Posted November 28, 2009 %20 is correct, And it (should) once downloaded be spaces. It's sometimes hard to modify code if the programmer was bent and made it (headers, code etc.) were made to strip out spaces. Best you can do is replace the "" with "-" so it'll appear as "Artist-Song.mp3", that is your best bet. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966727 Share on other sites More sharing options...
crazyjust Posted November 28, 2009 Author Share Posted November 28, 2009 If I make it add "-" for spaces it would be like Artist-Song-Title.mp3 if the title is 2 or more words. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966733 Share on other sites More sharing options...
mrMarcus Posted November 28, 2009 Share Posted November 28, 2009 try this: <?php // force to download a file $file = str_replace("\'","'",stripslashes($_GET['link']));//"http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3"; $filename = str_replace("-"," - ",$file); $filename = substr($filename,strrpos($filename,"/")+1); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\""); header("Content-Description: File Transfer"); @readfile($file); ?> That shows the code in a white page works perfect for me with this usage: http://localhost/dl.php?link=http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3 Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966766 Share on other sites More sharing options...
crazyjust Posted November 28, 2009 Author Share Posted November 28, 2009 Yes it does work ok. I'm sorry I didn't upload it correctly to my server. It doesn't do what I want it to though. That would make it appear as Title - - - Song - Title.mp3 Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966770 Share on other sites More sharing options...
crazyjust Posted November 28, 2009 Author Share Posted November 28, 2009 ok i'm wrong. It makes a file download but its not recognized as any file type so that wont work. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966774 Share on other sites More sharing options...
mrMarcus Posted November 28, 2009 Share Posted November 28, 2009 i wasn't paying attention .. the str_replace() is not necessary: <?php // force to download a file $file = str_replace("\'","'",stripslashes($_GET['link']));//"http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3"; $filename = substr($file,strrpos($file,"/")+1); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\""); header("Content-Description: File Transfer"); @readfile($file); ?> as i said, if i type: localhost/dl.php?link=http://www.crazyjust.com/files/2/20 Fingers - Choke My Chicken.mp3 where dl.php is the file i have the code in, i get prompted to download: 20 Fingers - Choke My Chicken.mp3, exactly as you see there. Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-966782 Share on other sites More sharing options...
crazyjust Posted December 1, 2009 Author Share Posted December 1, 2009 Thank you so much. That works perfect Quote Link to comment https://forums.phpfreaks.com/topic/183073-i-didnt-code-this-but-i-need-help-with-it/#findComment-968586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.