O PHP5 permite manipular arquivos externos, como, por exemplo, arquivos txt, assim como permite realizar tratamento de erro. A seguir, são apresentados o código em PHP5 que abre o arquivo hello.txt e um possível erro associado.
1 <?php
2 $file=fopen("hello.txt","r");
3 ?>
Warning: fopen(hello.txt) [function.fopen]: failed to open stream:
No such file or directory in xpto.php on line 2
Assinale a opção que apresenta o código correto para prevenir o erro em questão.
1 <?php
2 $file=fopen("hello.txt","r");
3 ?>
Warning: fopen(hello.txt) [function.fopen]: failed to open stream:
No such file or directory in xpto.php on line 2
Assinale a opção que apresenta o código correto para prevenir o erro em questão.
- A)<?php
if(feof("hello.txt")) {
echo("Arquivo não existe!");
} else {
$file=fopen("hello.txt","r");
}
?> - B)<?php
if(error().fopen("hello.txt")) {
exit("Arquivo não existe!");
} else {
$file=fopen("hello.txt","r");
}
?> - C)<?php
if(error_log("Warning: fopen(hello.txt)")) {
curl_error ("Arquivo não existe!");
} else {
$file=fopen("hello.txt","r");
}
?> - D)<?php
if(!file_exists("hello.txt")) {
die("Arquivo não existe!");
} else {
$file=fopen("hello.txt","r");
}
?>