423,688 Members | 2,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

Catch warnings

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Yeray Garcia wrote:
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?


========
<?php

$old_track = ini_set('track_errors', '1');

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

if (!@copy('no_file', '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 :
Jul 17 '05 #2

P: n/a
That is exactly what I was looking for.

Thanks a lot.
Yeray

Pedro Graca wrote:
Yeray Garcia wrote:
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?

========
<?php

$old_track = ini_set('track_errors', '1');

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

if (!@copy('no_file', '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


Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.