3 strange errors

Workarounds and usability notes.

3 strange errors

Postby John Robin Dove » Tue Mar 31, 2020 9:05 am

Hi Clifton,

I have not been able to make my recording system function without putting a js folder in both the ns7 and the ie5 folders.

Error no. 1 is to do with this. A folder called has been added to the ns7 folder using Powerpac Add Folders to Export tree but it is not displayed in red as it should be in the Powerpac Export Tree Manager. I know it's there because if I try to add it again I get a message telling me this name cannot be used and also it is always recreated by the export process. So it's not a great problem for me so far.

Error no. 2 is no longer a problem but extraordinary! I didn't believe it could happen but it did. In my code I often use local variables called myArray as you also do in many of your examples. In my XML file I had another array with this name: sharedActions.myArray. During the complicated loading process a local myArray variable was used in the TB part of the program to activate a function in the sharedActions section of my XML. The contents of this array was transferred to the sharedActions.myArray even though there was nothing in the code to explain how this could have happened! I corrected this error just by sending the parameters as a String rather than an array. As a precaution I have also changed the name of the array in the sharedActions object.

Error no. 3 I'm hoping you can do something about. Once again it is not a serious problem but it can be misleading. You rewrote a php file makeFolders.php for me:
Code: Select all
<?php
 $rtn = 'success'; //Set default to return true
    $serverPath = $_SERVER['DOCUMENT_ROOT'] . '/programs/';
    if ( isset($_POST['endPath']) ) {
        $endPath = $_POST['endPath'];
        if ( !file_exists($serverPath.$endPath) ) {
            if ( mkdir($serverPath.$endPath, 0777, true) ) { //may be true or false
                //All okay so we do nothing here
            } else {
                $rtn = "error: file";
            }
        } else {
            $rtn .= ": file already exists";
        }
    } else {
        $rtn = "error: invalid post"; //Failure to provide valid $_POST forces return as false
    }
    exit( "$rtn" );
?>

The trouble is it returns 'success' even when the directories have not been made. The exact mistake was that I sent "/programs/directory1/directory2 etc." but "/programs/" is not required because it is added in the php file.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: 3 strange errors

Postby Clifton » Tue Mar 31, 2020 4:02 pm

Error 1 and 2:
I've tried to duplicate this and cannot replicate it.

Error 3:
Here is a more feature-filled folder creation script. It returns a JSON string with success/error messages. If a subfolder exists, an error indice will be written to the array.
Code: Select all
<?php
   /* CLIFTON: This code provided AS IS.
               Creates a subpath of folders in /root/programs/...
               To debug or edit, enable echo and print_r() lines and run directily in browser:
                  http://[path]/file.php?endPath=/programs/dir1/dir2/myFolder/
   ***/
   $err = []; //Array to collect file operations
   $serverPath = $_SERVER['DOCUMENT_ROOT'] . '/programs';
   $endPath = isset($_POST['endPath']) ? $_POST['endPath'] : isset($_GET['endPath']) ? $_GET['endPath'] : '';
   
   if (empty($endPath)) {
      $err[] = $endPath ?: 'error: invalid post';
      exit( json_encode($err) );
   }
   
   $endPath = preg_replace("/(\/|\\\\){2,}/", "/", $endPath); //Remove multiple path separators
   $endPath = preg_replace("/^(\/|\\\\)?programs(\/|\\\\)?/", "", $endPath);
   
   //echo 'Splitting: ' . $endPath . '<br>' . $serverPath . '<br>';
   
   $endPath = preg_split("/\/|\\\\/", $endPath); //Create array of subfolders
   $endPath = array_values( array_filter($endPath, 'strlen') ); //Remove invalid subfolder names (empty values)
   
   foreach($endPath as $dir) {
      if (!file_exists("$serverPath/$dir")) {
         $tmp = @mkdir("$serverPath/$dir", 0777, true);
         if (!$tmp) {
            //Likely an invalid character in path; indicates problem with POST
            $err[] = "error: $dir could not be created!";
            break; //Every attempt to create a subfolder from this point on will also fail!
         } else {
            $err[] = "$dir created successfully!";
         }
      } else {
         $err[] = "error: $dir already exists!<br>";
      }
      $serverPath .= "/$dir";
   }
   
   //print_r($err) . '<br>';
   echo json_encode($err); //Always enable this line to get feedback to client applicaton
   
   exit();
?>
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: 3 strange errors

Postby John Robin Dove » Wed Apr 01, 2020 6:34 am

Thanks Clifton,

I now have more information about error no. 1. It is caused by the number of files that I have added.
Image
If I remove the bottom two files from the media folder the js folder in the ns7 is displayed normally. I guess I should have put the files in a separate folder rather than putting them all in the media folder. Users always do unexpected things! :roll:

I have also tried to reproduce error no. 2 in a test app but unsurprisingly I have not succeeded. Nevertheless I was not dreaming: the contents of the local array variable were indeed transferred to the sharedActions variable! I would have to send you masses of stuff to prove it so maybe we should just put it down to the ramshackle nature of my project. Anyway it was not difficult to solve the problem.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: 3 strange errors

Postby Clifton » Wed Apr 01, 2020 7:19 am

If you want a lot of files added to the [media] folder, just name a folder "media" in the book folder of your project and add it to the export file list at the root level. This will cause the [media] folder to be shown in red in the DHTML Export Tree Manager. During export, Toolbook will build the [media] folder and when the PowerPac takes over, it will add the relevant media items to the same folder. Just make sure none of your items are set to overwrite the native ones that ToolBook creates.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron