Ok I have been trying to work around this buggy situation, so here you have already parts of the solution since it may take sc years to realize that the generated code is wrong.
Suppose my application is called grid_filestorage. Then I have the files grid_filestorage_doc.php, grid_filestorage_js0.php, grid_filestorage_form0.php, grid_filestorage_nmutf8.php and some others that are less interesting.
In grid_filestorage_doc.php you will find this code (or similar according to your situation).
<?php
session_cache_limiter("");
session_start();
include_once 'grid_filestorage_nmutf8.php';
if (!empty($_GET))
{
foreach ($_GET as $nmgp_var => $nmgp_val)
{
$$nmgp_var = NM_utf8_decode(NM_utf8_urldecode($nmgp_val));
$$nmgp_var = str_replace('**Plus**', '+', $$nmgp_var);
}
}
if ($nm_cod_doc == "documento_db")
{
$NM_dir_atual = getcwd();
...
This should be:
<?php
session_cache_limiter("");
session_start();
include_once 'grid_filestorage_nmutf8.php';
if (!empty($_GET))
{
foreach ($_GET as $nmgp_var => $nmgp_val)
{
$$nmgp_var = NM_utf8_decode(NM_utf8_urldecode($nmgp_val));
$$nmgp_var = str_replace('**Plus**', '+', $$nmgp_var);
$$nmgp_var = str_replace('**Ecom**', '&', $$nmgp_var);
$$nmgp_var = str_replace('**Jvel**', '#', $$nmgp_var);
}
}
if ($nm_cod_doc == "documento_db")
{
$NM_dir_atual = getcwd();
...
You can verify that this is needed since the grid_filestorage_js0.php has the function nm_mostra_doc(campo1, campo2, campo3)
function nm_mostra_doc(campo1, campo2, campo3)
{
while (campo2.lastIndexOf("&") != -1)
{
campo2 = campo2.replace("&" , "**Ecom**");
}
while (campo2.lastIndexOf("#") != -1)
{
campo2 = campo2.replace("#" , "**Jvel**");
}
while (campo2.lastIndexOf("+") != -1)
{
campo2 = campo2.replace("+" , "**Plus**");
}
NovaJanela = window.open ("grid_filestorage_doc.php?script_case_init=<?php echo NM_encode_input($this->Ini->sc_page); ?>&script_case_session=<?php echo session_id() ?>&nm_cod_doc=" + campo1 + "&nm_nome_doc=" + campo2 + "&nm_cod_apl=" + campo3, "ScriptCase", "resizable, scrollbars");
}
Here campo2 is the filename, so you can see that the nm_nome_doc parameter has the value of the filename which is passed on to grid_filestorage_doc.php
But we are not there yet.
There is another peice that is buggy in grid_filestorage_doc.php. If you want to view a file instead of downloading it, then under ie and some other browsers it
is normal to send the mime info along. The generated code from scriptcase does not handle that properly. Apparently the guys from netmake did not test with
chrome, ie8, opera, maxthon, firefox, safari, ipad safari and various other browsers. I dont have the time to test every browser so I only tested the big names on
various operating systems.
The corrected code is:
if (is_file($trab_doc))
{
header("Pragma: public", true);
header("Content-type: application/force-download");
$sProtectedFilename = str_replace(array(' ', "'", '!', ',', '-', '+'), array('__SC_SPACE__', '__SC_QUOTES__', '__SC_EXCLAMATION__', '__SC_COMMA__', '__SC_MINUS__', '__SC_PLUS__'), $nm_nome_doc);
$sProtectedFilename = urlencode($sProtectedFilename);
$sProtectedFilename = str_replace(array('__SC_SPACE__', '__SC_QUOTES__', '__SC_EXCLAMATION__', '__SC_COMMA__', '__SC_MINUS__', '__SC_PLUS__'), array(' ', "'", '!', ',', '-', '+'), $sProtectedFilename);
if (isset($_SERVER['HTTP_USER_AGENT']) && false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'chrome'))
{
header("Content-Disposition: attachment; filename=\"" . $sProtectedFilename . "\"");
}
elseif (isset($_SERVER['HTTP_USER_AGENT']) && false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'applewebkit'))
{
header("Content-Disposition: attachment; filename=\"" . $nm_nome_doc . "\"");
}
elseif (function_exists('NM_utf8_urldecode') && $nm_nome_doc != NM_utf8_urldecode($nm_nome_doc))
{
header("Content-Disposition: attachment; filename=\"" . $nm_nome_doc . "\" filename*=UTF-8''" . $sProtectedFilename);
}
else
{
//header("Content-Disposition: attachment; filename=\"" . $sProtectedFilename . "\""); //<<<<wrong this one will will cause R&D.doc to be downloaded as R%26D.doc whcih is not what we want. We want the real filename.
[color=red]header("Content-Disposition: attachment; filename=\"" . $nm_nome_doc . "\"");
}
readfile($trab_doc);
}
...
I havent yet figured out why I can not upload a file named file+test.doc I know that it is because of the + but for windows that is no argument. Such a filename is completely legit. The conventions in windows are here: http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx and http://en.wikipedia.org/wiki/Filename
I have to do some more testing on other browsers to see if it works. This is not the end of it since there are more bugs in the generated code. But so far a few bugs are fixed. Lets wait and see what scriptcase does with these details on how to fix the code… They have my email…
Be aware: any character>=char(128) is not working, filenames with + % still wont upload.
and & seem to work. So expect a few changes in this code…
I hope this helps someone…