Link to home
Start Free TrialLog in
Avatar of mmarth
mmarth

asked on

trouble writing to a log file

i can not write to a log file from within a function in blog/wp-content/plugins/nextgen-gallery/admin/functions.php

i can write to it from within blog/wp-content/plugins/nextgen-gallery/admin/addgallery.php which calls a class method in functions.php

the function nggAdmin::import_gallery($gallerypath);

both files are in the same directory.

does anyone have an idea what is going on?
Avatar of Sudaraka Wijesinghe
Sudaraka Wijesinghe
Flag of Sri Lanka image

Could you please explain a bit how and where to you write the log file. And do you get any errors?
Avatar of mmarth
mmarth

ASKER

there are no seen errors.

i have tried :
               define('ABSPATH', dirname(__FILE__) . '/');
               $theFile = ABSPATH . "wp-content/plugins/nextgen-gallery/admin/log.txt";
               if (is_writable($theFile))
               {
                  $res = error_log("new log addgallery " . $numSelected . " \r\n" , 3, $theFile);
                  if ($res===false) die('error_log unknown failure');
               }
               else
               {
                  die('cant write:'.$theFile);
               }

and :

   nggAdmin::logtask($variableToPass);

   function logtask($error)
   {
      define('ABSPATH', dirname(__FILE__) . '/');
      $theFile = ABSPATH . "wp-content/plugins/nextgen-gallery/admin/log.txt";
      touch($theFile);
      $fs = fopen($theFile,"a");
      $int=fwrite($fs,  "check  - $error\r\n");
      fclose ($fs);
   }
Are you checking is_writable on a non-existing file? you might need to touch it before checking if it's writable.

define('ABSPATH', dirname(__FILE__) . '/');
               $theFile = ABSPATH . "wp-content/plugins/nextgen-gallery/admin/log.txt";

               @touch($theFile);
               if (is_writable($theFile))
               {
               .
               .
               .

Open in new window

Avatar of mmarth

ASKER

i can write to the file from another program in the same directory. the problem comes when i try to call the method from another program. both files are in the same directory. i can write from the first one, but not from the function in the other whch is called from the first program.
SOLUTION
Avatar of Sudaraka Wijesinghe
Sudaraka Wijesinghe
Flag of Sri Lanka image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shinesh Premrajan
Try this, place this code in the top of the script

ini_set("display_errors","1");
error_reporting(E_ALL);

It seems your error reporting is not enabled.

Hope this helps
Avatar of mmarth

ASKER

the program is blocking any info from the included file, so i could not check any variable created there. i could write to the database and then i could proceed. thank you for the ideas.