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 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 :
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
by: Samuel |
last post by:
Imagine you have the following code:
try
{
...
}
catch (ThreadAbortException eThread)
{
if (WorkStopped != null) WorkStopped(this, EventArgs.Empty)
}
|
by: Steve |
last post by:
I have some general catch clauses in my app as follows:
try
{
}
catch(Exception ex)
{
}
try
|
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...
|
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)
{
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |