SC7 does not work on mobile browsers, download files doesnt work on ie, multiple bugs

BUG 1: As the topic says, when I build a website with SC 7 it simply doesnt work unless I set my browser in desktop mode (android tested with chrome, maxthon, firefox).

A file download doesnt work either, the code that is generated is basically not tested well


   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 . "\"");
       }


       readfile($trab_doc);
   } 

BUG 2: This generated code does NOT allow ie 6,7,8 to download properly
This adapted one does:


  if (is_file($trab_doc))  
   { 
//       header("Pragma: public", true);
//       header("Content-type: application/force-download");
if (isset($_SERVER['HTTP_USER_AGENT']) && false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'applewebkit')){
  header("Content-Description: File Transfer");
  header("Expires: 0");
  header("Pragma: public");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
}else{
       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 . "\"");
       }
header('Content-Transfer-Encoding: binary');
header("Content-Length: ".filesize($trab_doc));
       readfile($trab_doc);
   } 

in SC6 bug 1 didnt occur… There browsing with mobile firefox/maxthon/safari/chrome worked…

FIX IT NOW please… I dont want to hack in the generated code to circumvent your bugs.

I posted this through.

The proper generated code appears to be:


   if (is_file($trab_doc))  
   { 
	   $finfo=finfo_open(FILEINFO_MIME_TYPE);
       header("Content-type: ".finfo_file($finfo));
	   finfo_close($finfo);
//header("Content-Description: File Transfer");
//header("Expires: 0");
//header("Pragma: public");
//header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

//       header("Content-Disposition: attachment; filename=\"" . urlencode($nm_nome_doc) . "\" filename*=UTF-8''" . urlencode($nm_nome_doc));
       $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 . "\"");
       }
//header('Content-Transfer-Encoding: binary');
//header("Content-Length: ".filesize($trab_doc));
       readfile($trab_doc);

This one lets you open a pdf and a docx file on the ipod/ipad it causes download on the standard android browser and it works on safari on windows (thus also on osx) and on maxthon and firefox and internet explorer.

There is a

serious bug

on scriptcase 6 in the file name field type where downloading a file causes a buggy filename to appear. Apparently that at least seems to be fixed in sc7.

So for people that use the file downloader and seem to have problems with downloading the files check your application dir, check the *_doc.php file and find the part that looks like what I pasted above (the first section) and correct it with the knowledge from the 3rd section…

What really really annoys me is that there is no proper testing being done on various machines at the scriptcase HQ.
I think you guys should buy a couple of devices (ipod/ipad/android phone or tablet/mac osx/windows rt/windows xp/windows 7) and put some browsers on all of those machines (chrome/firefox/internet explorer 7,8,9 and up/maxthon/safari!!). Then have someone test the lastest updates in details on all those browsers and machines. Create proper test scripts, assign someone that is just performs those scripts and that has enough knowledge to see it isnt working properly. Then fix it all before you release a new update.

Hello,

Issue reported to our bugs team.

regards,
Bernhard Bernsmann

I have given the main way to resolve the uploader but some of the other bugs I showed are also not fixed (see the rest of the forum).
I dont understand why that takes so long, specially since I generally give more then enough details to resolve it or work around it…

I made a copy paste error I saw.

if (is_file($trab_doc))
{
$finfo=finfo_open(FILEINFO_MIME_TYPE);
header("Content-type: ".finfo_file($finfo));
finfo_close($finfo);
should be
if (is_file($trab_doc))
{
$finfo=finfo_open(FILEINFO_MIME_TYPE);
header("Content-type: ".finfo_file($finfo,$trab_doc));
finfo_close($finfo);

Here is the newer version of the code. Apparently the previous code also fails on some filetypes on some browsers.
This on is tested on windows: IE8, firefox, safari, maxthon 4,chrome android: firefox, standard google browser, maxthon 4 ipad:safari, firefox
Be aware that the standard apache mime types have incorrect values for some types, so does finfo_open. For example .eml is supposed to be message/rfc822


  if (is_file($trab_doc))  
   { 
//if not applewebkit  so if ie/opera/.. and alike
if (isset($_SERVER['HTTP_USER_AGENT']) && (false == strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'applewebkit'))){
  header("Content-Description: File Transfer");
  header("Expires: 0");
  header("Pragma: public");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  //       header("Content-Disposition: attachment; filename=\"" . urlencode($nm_nome_doc) . "\" filename*=UTF-8''" . urlencode($nm_nome_doc));
  $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 . "\"");
  }
  header('Content-Transfer-Encoding: binary');
  header("Content-Length: ".filesize($trab_doc));
}else{
   $finfo=finfo_open(FILEINFO_MIME_TYPE);
   if (strtolower(substr($filename,-4))=='.eml'){
     echo header("Content-type: message/rfc822");
   }else{
     echo header("Content-type: ".finfo_file($finfo,$trab_doc));
   }
   finfo_close($finfo);
   $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 . "\"");
   }
}
       readfile($trab_doc);
   } 

Hello,

I simulated your problem on my system and it worked normally.

Only the selected table from the database and request to create.

You did anything different? If possible illustrate step by step by explicative images.

For this you need to use a windows server. Then upload files with strange character names.
That should show that the filenames sometimes go wrong (use + and & and | and so on and you’ll see).
For downloading files you should simple use a simple editable grid with uploads for file and try yto download then.
Anyway the default scriptcase code to download a file is not working for some browsers (running on a windows server).
I tried to circumvent the bugs in the generated code. Simply said, downloading images with strange charcters fails on some characters, and it is not possible with the current code to force an open as
box which makes it useless for iphone/ipod since there is no filetype given. Hence a standard program to open a file isnt shown…
At least the generated code should show the option to either use application/download AND downloading using the mime type (be aware the apache mimetype has some bugs and eml mail files als doesnt work well for php mime types).
That you simulated my ‘problem’ is because what I showed was the fixed version from the generated code. Scriptcase creates code that simple doesnt work properly in various cases.

Hello moderator, I know this thread is old but it is pertinent with the error I have in a scriptcase 9 application (now), I just want to know how to correct it, thanks for your collaboration.

This forum is maintained by volunteers like me. I have no clue here. Sorry for that.