No announcement yet.

Problem with form with Document (File name) type field

  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with form with Document (File name) type field

    I have an utterly simple form with only two fields on it from a simple table with NR and FILENAME as fields. I am using this to make a small test case for document uploads.
    In this application settings I have the documents path: /scriptcase/app/TestConnection2/files and the Image Directory also: /scriptcase/app/TestConnection2/files
    The filename is a Document (File name) type.
    I get my window as below (1.jpg).
    But when I click my filename then I can not download it. This is rather peculiar.
    If I change the field to the Image (File name) type then the image gets properly displayed.
    As mentioned before, both paths are the same. I would have expected the document to be downloadable. Has anyone ever got this to work properly?

    With the Document (file name) type i get a "The file does not exist: wmovies2_1024.jpg" error.. Really weird.....
    Attached Files

  • #2
    I hate bugs

    On further analysis:
    On the filename there is the javascript:nmmostra_doc('0','wmovies2_1024.jpg',;f orm_SCRIPTCASE_TST_FILEUPLOAD') call.
    This results in a window that opens with form_SCRIPTCASE_TST_FILEUPLOAD_doc.php with a number of parameters.
    The parameters become variables in the routine as far as I can see.

    The php code of the generated php file:
       include_once 'form_SCRIPTCASE_TST_FILEUPLOAD_nmutf8.php';
       if (!empty($_GET))
           foreach ($_GET as $nmgp_var => $nmgp_val)
                $$nmgp_var = NM_utf8_decode(NM_utf8_urldecode($nmgp_val));
       if ($nm_cod_doc == "documento_db")
           $NM_dir_atual = getcwd();
           if (empty($NM_dir_atual))
              $str_path_sys    = (isset($_SERVER['PATH_TRANSLATED'])) ? $_SERVER['PATH_TRANSLATED'] : $_SERVER['SCRIPT_FILENAME'];
              $str_path_sys    = str_replace("\\", '/', $str_path_sys);
              $str_path_sys    = str_replace('//', '/', $str_path_sys);
               $sc_nm_arquivo = explode("/", $_SERVER['PHP_SELF']);
               $str_path_sys  = str_replace("\\", "/", str_replace("\\\\", "\\", getcwd())) . "/" . $sc_nm_arquivo[count($sc_nm_arquivo)-1];
           $str_path_web  = $_SERVER['PHP_SELF'];
           $str_path_web  = str_replace("\\", '/', $str_path_web);
           $str_path_web  = str_replace('//', '/', $str_path_web);
           $root          = substr($str_path_sys, 0, -1 * strlen($str_path_web));
           $trab_doc      = $root . $_SESSION['scriptcase']['form_SCRIPTCASE_TST_FILEUPLOAD']['glo_nm_path_imag_temp'] . "/sc_" . $nm_nome_doc;
           $path_raiz = $_SESSION['sc_session'][$script_case_init][$nm_cod_apl]['path_doc'];        <<<<<<<<<here is where I apparently go with the code
           $sub_path  = $_SESSION['sc_session'][$script_case_init][$nm_cod_apl]['sub_dir'][$nm_cod_doc];
           $trab_doc = $path_raiz . $sub_path . "/" . $nm_nome_doc;                 <<<<<<< thus the path is coming from the document path of the application with the subdir (none for me) added followed by a slash and the filename. Then any \\ is converted to / as well as \\ converted to / for making the correct path. 
           $trab_doc = str_replace("\\", "/", $trab_doc);
           $trab_doc = str_replace("//", "/", $trab_doc);
           echo "Doc file path:" . $trab_doc . "<br>";
       if (is_file($trab_doc))         <<<<apparently the error is here... :(
           header("Content-type: application/force-download");
           header("Content-Disposition: attachment; filename=\"" . urlencode($nm_nome_doc) . "\" filename*=UTF-8''" . urlencode($nm_nome_doc));
           $STR_lang    = (isset($_SESSION['scriptcase']['str_lang']) && !empty($_SESSION['scriptcase']['str_lang'])) ? $_SESSION['scriptcase']['str_lang'] : "en_us";
           $NM_arq_lang = "../_lib/lang/" . $STR_lang . ".lang.php";
           if (is_file($NM_arq_lang) && $STR_lang != "en_us")
               $Lixo = file($NM_arq_lang);
               foreach ($Lixo as $Cada_lin) 
                   $Tst = explode("=", $Cada_lin); 
                   if (strpos($Tst[0], "lang_errm_fnfd") !== false)
                       $Nm_lang['lang_errm_fnfd'] = substr(trim($Tst[1]), 1, -2);
               $Nm_lang['lang_errm_fnfd'] = "The file does not exist";
           echo $Nm_lang['lang_errm_fnfd'] . ": " . $nm_nome_doc;
    So now my result is:
    Doc file path:/scriptcase/app/TestConnection2/files/wmovies2_1024.jpg
    The file does not exist: wmovies2_1024.jpg

    The odd thing: the path seems correct and the file is absolutely there...
    The proof is in the fact that if it is an image file path that it does work....
    So please fix this as asap....

    Apparently the is_file is delivering false according to echo "is_file:".var_dump(is_file($trab_doc))."<br>" ;
    even tho the path is correct.. Very very odd...
    Last edited by rr; 01-23-2013, 08:45 AM. Reason: Update


    • #3
      It seems that is_file is failing because the path is relative. Of course that made sense, so now I put an absolute path in there it is (finally) fixed..
      This show the importance of some of the php code tho. Luckily one question solved..


      • #4
        It appears there still is a bug in there. These 2 lines make it impossible for an unc path to work.
        $trab_doc = str_replace("\\", "/", $trab_doc);
        $trab_doc = str_replace("//", "/", $trab_doc);
        Every so (also the first) // gets translated to /. Every \\ gets translated to \ but \\ is a single backslash. So this piece is wrong (see
        Hence an UNC path like so: \\\files\SCRIPTCASE_TESTDIR would go very wrong (notice the \f that the path isnt properly translated to a real php string). This one // also fails due to the first // becoming \

        Anyway I am willing to bet that scriptcase screws up unc paths in other places as well.
        Last edited by rr; 01-23-2013, 10:45 AM.


        • #5
          So now the question remains, how can I save on an unc path with scriptcase? The code that is generated is obviously wrong.
          In order to get to a remote dirve you MUST run the apache service under a user that has network rights. I basically assume this common knowledge, just change the user the service is running on.
          So you could map a drive letter, but that would not work if your apache runs as a service. Basically you can not map a drive as a service unless you use elevate the privileges or write some php code that does the drive mapping and you execute that the first time an app runs.
          The other more permanent solution would be to make a link using mklink (see )
          So go to the dir where you want your files stored and type the command. In my test case in the c:\Program Files (x86)\NetMake\v6\wwwroot I would run a command: mklink /d storedfiles \\\files\SCRIPTCASE_TESTDIR

          So guys please fix the bugs in this area, if unc paths would be working properly then this would be a breeze. Please also fix this in v7 as well.


          • #6
            Hello rr,

            Are you working with Linux? What distribution? Windows?

            Please contact our support regarding this issue. Our chat is active on workdays from 8:00am to 6:00pm, and our ticket system is always available.

            I will also pass it on to our bugs team.

            Bernhard Bernsmann


            • #7
              No we are working on Windows 2008 server. I've brought this issue too under attention of mr.lacerda.
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development


              • #8
                Hi rr,

                I'm not sure to be on topic but just for your info I did something similar. I hope that it will be of some help for you.
                After many and many temptatives... I realized that the folder where the file are temporarely stored is not as expected under f/_lib/file/doc folder.
                In my case I discovered them under: /_lib/file/doc/scriptcase/file/doc

                This is a piece of code I used to manage an uploading process:

                $path = $_SESSION['scriptcase']['upload_file_csv_fmi']['glo_nm_path_doc'];

                //echo " PATH primo pezzo " . $path;

                // OLD $file_dir = $path . '/' . {upload};
                $file_dir = $path . '/scriptcase/file/doc/' . {upload};

                [glo_upload_file_path] = $file_dir;

                $file_path = $path . '/scriptcase/file/doc/';

                [glo_file_path] = $file_path;

                //echo "FINAL PATH + FILENAME ".[glo_upload_file_path];
                $lines = file($file_dir);

                Attached Files