0

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!!

4

6 に答える 6

1

を使用してみてください

file_get_contents(); 

fopen()の代わりに関数。

于 2009-05-20T13:50:58.300 に答える
1

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:

$file = @fopen("xyz.com","rb");

if(!$file)
{
    mail($to, $subject, $message, $from);
    die();
}
于 2009-05-20T09:29:36.707 に答える
0

fopenメソッドの先頭から「@」文字を削除します(@記号が存在すると、phpによるエラーメッセージが抑制されます)。これにより、phpがそのファイルを開くことができないと考える理由が説明されます。ファイルへのパスまたはファイルの権限が無効です。

于 2009-05-20T09:39:04.127 に答える
0

エラーメッセージとは何ですか?それがなくても問題を推測することができます。

あなたのiniでurlfopenは常に許可されていますか?たぶん、この値はini_set()でどこかをオーバーライドしますか?

確かに、そのURLは正しく、ホストは生きていますか?

最後に、代わりにfsockopenを使用することをお勧めします。より柔軟なリモート接続、それらのエラー処理、および接続タイムアウトを設定する可能性を提供します。

于 2009-05-20T11:10:02.667 に答える
0

ちなみに、エラーが発生した場合は$ flag=1に設定しています。しかし、前回エラーが発生し、今回はエラーが発生しなかった場合はどうなりますか?(その後、$ flagは前回から1のままです)。

于 2009-05-20T09:38:11.773 に答える
0

@ 記号はエラーを抑制するため、$flag は決して設定されません

于 2010-08-09T15:34:56.717 に答える