I'm using @fopen to open a file in "rb" mode. the file that im opening here is running with no errors but if i open that file using @fopen then it is giving error.
code is something like this---
$file = @fopen("xyz.com","rb") or $flag=1;
if($flag==1)
{
mail($to, $subject, $message, $from);
die();
}
sometimes it opens up without sending any error mail but sometimes it starts giving so many error mails.
what is the solution to open this url without having any error mail? plz help!!
What is error message? We can just guess about the problem without it.
Is url fopen always allowed in your ini? Maybe this value overrides somewhere with ini_set()?
Are you sure, that url is correct and host is alive?
Finally, I recommend to use fsockopen instead. It provides more flexible remote connections, error handling for them and possibility to set the connection timeout.
If you're trying to open a URL (presuming from the 'xyz.com' you included), then you need to include the schema declaration before it. E.g. http://xyz.com, otherwise PHP will attempt to open a local file. If you're referring to a local file, make sure to escape any back-slashes if you're on Windows.
However, there's nothing else inherently wrong with the rest of your code sample that should cause a problem. @ simply suppresses error outputs, so it won't be causing any odd behaviour in and of itself.
Though, that said, a better way to handle it might be to do this:
Try to use the
function instead of fopen().
by the way, you are setting $flag = 1 when there is an error. but what if there was an error last time and this time there is no error? (then $flag is still 1 from the previous time).
The @ symbols suppresses errors so $flag will never be set
remove the '@' charactor from the start of the fopen method, (ther presence of the @ symbol supresses any php driven error message) this will give you the explanation of why php thinks you cant open that file - i would hazard a guess either the path to the file or the permissions of the file are invalid.