Catch warnings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yeray Garcia

    Catch warnings

    Hi,

    I'm using php to delete, rename, copy... some files. Sometimes php has
    no permissions to do these operations, so the unlink(), rename(),
    copy(), ... methods return a warning and send it to the browser.

    What I'd like to do is to get these warning messages and save them in a
    variable to print them somewhere else later so that it look nicer.

    With the @ before the methods I can ignore warnings/errors but that's
    not exactly what I want.

    For example, when mysql returns an error, I can get it with the
    mysql_error() method.

    Has anyone an idea, how could I do this?

    Thanks
    Yeray
  • Pedro Graca

    #2
    Re: Catch warnings

    Yeray Garcia wrote:[color=blue]
    > I'm using php to delete, rename, copy... some files. Sometimes php has
    > no permissions to do these operations, so the unlink(), rename(),
    > copy(), ... methods return a warning and send it to the browser.
    >
    > What I'd like to do is to get these warning messages and save them in a
    > variable to print them somewhere else later so that it look nicer.
    >
    > With the @ before the methods I can ignore warnings/errors but that's
    > not exactly what I want.
    >
    > For example, when mysql returns an error, I can get it with the
    > mysql_error() method.
    >
    > Has anyone an idea, how could I do this?[/color]

    ========
    <?php

    $old_track = ini_set('track_ errors', '1');

    if (!@unlink('no_f ile')) {
    echo $php_errormsg, "\n";
    }

    if (!@copy('no_fil e', 'some_file')) {
    echo $php_errormsg, "\n";
    }

    ini_set('track_ errors', $old_track);

    ?>
    ========


    And the output is:

    No such file or directory
    failed to open stream: No such file or directory


    See http://www.php.net/manual/en/ref.errorfunc.php


    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • Yeray Garcia-Quintana

      #3
      Re: Catch warnings

      That is exactly what I was looking for.

      Thanks a lot.
      Yeray

      Pedro Graca wrote:[color=blue]
      > Yeray Garcia wrote:
      >[color=green]
      >>I'm using php to delete, rename, copy... some files. Sometimes php has
      >>no permissions to do these operations, so the unlink(), rename(),
      >>copy(), ... methods return a warning and send it to the browser.
      >>
      >>What I'd like to do is to get these warning messages and save them in a
      >>variable to print them somewhere else later so that it look nicer.
      >>
      >>With the @ before the methods I can ignore warnings/errors but that's
      >>not exactly what I want.
      >>
      >>For example, when mysql returns an error, I can get it with the
      >>mysql_error () method.
      >>
      >>Has anyone an idea, how could I do this?[/color]
      >
      >
      > ========
      > <?php
      >
      > $old_track = ini_set('track_ errors', '1');
      >
      > if (!@unlink('no_f ile')) {
      > echo $php_errormsg, "\n";
      > }
      >
      > if (!@copy('no_fil e', 'some_file')) {
      > echo $php_errormsg, "\n";
      > }
      >
      > ini_set('track_ errors', $old_track);
      >
      > ?>
      > ========
      >
      >
      > And the output is:
      >
      > No such file or directory
      > failed to open stream: No such file or directory
      >
      >
      > See http://www.php.net/manual/en/ref.errorfunc.php
      >
      >[/color]

      Comment

      Working...