Hi all - it's 6am and I'm bailing with a cry for help on this one ...
I have a page that lists filenames and the directories they're in. I could set the filenames to be hyperlinks to the files, so they can be clicked or rightclick/save-as'd, but instead I make the whole table cell the filename is in a big mouseover with an onclick event of window.location=path\filename. I found I had to replace ' for %27 in the path/fname strings to avoid ruining the 'quotes'.
However, the problem with that is streamable filetypes eg mp3/wmv open instead of save, which the end user would rather have, but with the cell link method they can't rightclick/save-as.
So I've tried now pointing the table links back at the php page with path and fname GET variables that are read back in and used in a header to force a download, aka open the open/save dialog box.
This works, but the problem is now that the filename it gives you to 'save as' isn't the same as the actual filename, ie it has _ instead of spaces and such. I've tried various encoding and decoding for the link and the variable the header uses but the best I've got has spaces not _ but the ' that was encoded as %27 is shown as _' and I can't get round it. Here's the current code snippets, you can see the old window.location html cmomented out.
This is at the very top of the php page
This is in the html tables
All help appreciated guys! Of course, if there was a javascript way to prompt the save-target-as box or whatever, that'd be perfect, but there isn't afaik. If anyone has a better way than mine to do this too, shout too
_________________________________
Leozack
I have a page that lists filenames and the directories they're in. I could set the filenames to be hyperlinks to the files, so they can be clicked or rightclick/save-as'd, but instead I make the whole table cell the filename is in a big mouseover with an onclick event of window.location=path\filename. I found I had to replace ' for %27 in the path/fname strings to avoid ruining the 'quotes'.
However, the problem with that is streamable filetypes eg mp3/wmv open instead of save, which the end user would rather have, but with the cell link method they can't rightclick/save-as.
So I've tried now pointing the table links back at the php page with path and fname GET variables that are read back in and used in a header to force a download, aka open the open/save dialog box.
This works, but the problem is now that the filename it gives you to 'save as' isn't the same as the actual filename, ie it has _ instead of spaces and such. I've tried various encoding and decoding for the link and the variable the header uses but the best I've got has spaces not _ but the ' that was encoded as %27 is shown as _' and I can't get round it. Here's the current code snippets, you can see the old window.location html cmomented out.
This is at the very top of the php page
Code:
if ($_GET['fname']) {
//$path = urluncode($_GET['path']);
//$fname = urluncode($_GET['fname']);
$path = $_GET['path'];
$fname = $_GET['fname'];
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.urlrecode($fname));
if ($path != "") { header('Content-Length: '.filesize($path.'/'.$fname)); }
else { header('Content-Length: '.filesize($fname)); }
//if ($path != "") { readfile($path.'/'.$fname) OR error('Error Reading File'); }
//else { readfile($fname) OR error('Error Reading File'); }
}
function urlcode($stringname) {
return str_replace(" ","%20",str_replace("'","%27",$stringname));
}
function urlrecode($stringname) {
return str_replace(" ","%20",str_replace("_","%20",$stringname));
}
This is in the html tables
Code:
$showname = $filename;
$filename = $subdir.$filename;
echo "
<tr style=\"font:14px Arial\"
onmouseover=\"bgColor='8181CC'; style.cursor='pointer'; return true\"
onmouseout=\"bgColor=''; return true\"
onclick=\"window.location='index.php?path=".urlcode($subdir)."&fname=".urlcode($showname)."'\">
<!--
onclick=\"window.location='".urlcode($filename)."'\">
!-->
<td style=\"color:blue\">$showname</td>
</tr>
All help appreciated guys! Of course, if there was a javascript way to prompt the save-target-as box or whatever, that'd be perfect, but there isn't afaik. If anyone has a better way than mine to do this too, shout too
_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);