473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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
Jul 17 '05 #1
2 33834
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Gianni Mariani | last post by:
I have a couple of template methods that take any integer type however, the first "if" statement becomes a constant expression when T is an unsigned type. #include <limits> template...
6
by: Ivan Shevanski | last post by:
Here's a noob question for everyone (I'm not sure if my first message got through, is had a "suspicious header" so sorry for double post is so), is there a way to turn off syntax warnings or just...
2
by: Samuel | last post by:
Imagine you have the following code: try { ... } catch (ThreadAbortException eThread) { if (WorkStopped != null) WorkStopped(this, EventArgs.Empty) }
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
2
by: sbalak | last post by:
I am writing code in C# and I wanted a basic solution: In Try / Catch block, I want to get a general Exception. So, I write code as: try { // do something } catch (SomethingException ex) {
6
by: aioe.cjb.net | last post by:
So, I was planning on ridding my VS2005 solution of all warnings, but the ones sounding "The variable 'ex' is declared but never used" in catch-blocks, are causing a headache. I have several...
2
by: Sergei Shelukhin | last post by:
Hi. I need to handle warnings in incorrect regular expressions executed using preg_match. Warnings shouldn't appear, instead I want to output some generic message like: "Bad regex: $regex" and...
4
by: RP | last post by:
In certain code blocks I don't want to do anything when an error is raised. I simply want that application must remain stable instead of crash. For the following code, is there a way to ignore...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.