给我错误的代码行是:
while (!feof($handle)) {
$conteudo .= fread($handle, 1024);
}
错误是:
[14-Jul-2016 16:39:42 UTC] PHP Warning: feof() expects parameter 1 to be resource, boolean given in /home/brazpayc/public_html/wp-content/themes/brazpay/page-42.php on line 118
[14-Jul-2016 16:39:42 UTC] PHP Warning: fread() expects parameter 1 to be resource, boolean given in /home/brazpayc/public_html/wp-content/themes/brazpay/page-42.php on line 119
我不知道这是否足够信息,我希望有人可以帮助我。
<?php
$brazpay = get_template_directory();
$brazpay_uri = get_template_directory_uri();
if (isset($_GET['n'])) {
$n = intval($_GET['load']);
$l = explode(",", $_GET['ld']);
brazpay_posts($n, $l);
}
if (isset($_GET['submit'])) {
$user_name = $_GET['username'];
$user_cpf = $_GET['usercpf'];
$user_cnjp = $_GET['usercnjp'];
$user_street = $_GET['userlocat'];
$user_number = $_GET['usernumber'];
$user_complement = $_GET['usercomplement'];
$user_district = $_GET['userbarrio'];
$user_state = $_GET['userstate'];
$user_city = $_GET['usercity'];
$user_postcode = $_GET['usercep'];
$user_country = (int)$_GET['usercountry'];
$user_value = (int)$_GET['uservalue'];
if ($user_cpf != '' && $user_cnjp == ''){
$user_code = "<cpf>$user_cpf</cpf>";
} elseif ($user_cnjp != '' && $user_cpf == '') {
$user_code = "<cnjp>$user_cnjp</cnjp>";
} else {
die("Fatal error cpf $user_cpf and cnjp $user_cnjp");
}
$URL = "http://boleto.msbbank.com.br/boleto.php";
$n_website = '20468565324-1'; //identificador único adquirido para acesso ao sistema – unique website ID
$password = '1e$ha!.'; //senha adquirida para acesso ao sistema - password
$uid = uniqid(); //identificador único da transação no website – unique transaction ID
$name = $user_name; //'Daniel Rodrigues'; //nome do sacado – buyer’s name
$identificador = $user_cpf; //'11091866732'; //CPF do sacado – buyer’s tax ID
$street = $user_street; //'Rua Moraes e Silva'; //endereço do sacado – buyer’s street address
$number = $user_number; //'98'; //número do endereço do sacado – buyer’s house number
$complement = $user_complement; //'Apartamento 404'; //complemento do endereço do sacado – buyer’s address complement
$district = $user_district; //'Tijuca'; //bairro do sacado – buyer’s neighborhood
$state_province = $user_state; //RJ'; //estado do sacado – buyer’s state
$city = $user_city; //'Rio de Janeiro'; //cidade do sacado – buyer’s city
$postcode = $user_postcode; //'20271-030'; //CEP do sacado – buyer’s ZIP code
$country = $user_country; //073; //país do sacado – buyer’s country
$value = $user_value; //100.00; //valor do boleto – amount
$product = 'Produto 1'; // Nome do produto
$url_return = ''; // URL de retorno
// $URL = "http://boleto.msbbank.com.br/boleto.php";
// $n_website = '20468565324-1'; //identificador único adquirido para acesso ao sistema – unique website ID
// $password = '1e$ha!.'; //senha adquirida para acesso ao sistema - password
// $uid = uniqid(); //identificador único da transação no website – unique transaction ID
// $name = 'Daniel Rodrigues'; //nome do sacado – buyer’s name
// $identificador = '11091866732'; //CPF do sacado – buyer’s tax ID
// $street = 'Rua Moraes e Silva'; //endereço do sacado – buyer’s street address
// $number = '98'; //número do endereço do sacado – buyer’s house number
// $complement = 'Apartamento 404'; //complemento do endereço do sacado – buyer’s address complement
// $district = 'Tijuca'; //bairro do sacado – buyer’s neighborhood
// $state_province = 'RJ'; //estado do sacado – buyer’s state
// $city = 'Rio de Janeiro'; //cidade do sacado – buyer’s city
// $postcode = '20271-030'; //CEP do sacado – buyer’s ZIP code
// $country = 073; //país do sacado – buyer’s country
// $value = 100.00; //valor do boleto – amount
// $product = 'Produto 1'; // Nome do produto
// $url_return = ''; // URL de retorno
$xml = "<requisicao-boleto>
<website>
<n_website>{$n_website}</n_website>
<password>{$password}</password>
</website>
<sacado>
<name>{$name}</name>
{$user_code}
<address>
<street>{$street}</street>
<complement>{$complement}</complement>
<number>{$number}</number>
<district>{$district}</district>
<state_province>{$state_province}</state_province>
<city>{$city}</city>
<postcode>{$postcode}</postcode>
<country>{$country}</country>
</address>
</sacado>
<dados_boleto>
<product>{$product}</product>
<reference>{$uid}</reference>
<value>{$value}</value>
</dados_boleto>
</requisicao-boleto>";
$xml = preg_replace('/\s(?=\s)/', '', $xml);
$xml = "xml=" . $xml;
$n = strlen($xml);
$opts = array(
'http' => array(
'method' => "POST",
'header' => "User-Agent: My Own Http Client\r\n" .
"Content-length: " . $n . "\r\n",
'content' => $xml
)
);
$context = stream_context_create($opts);
$handle = fopen($URL, 'r', false, $context);
$conteudo = '';
while (!feof($handle)) {
$conteudo .= fread($handle, 1024);
}
$content = (string)$conteudo;
fclose($handle);
$local = fopen($brazpay."/boletos/".$uid.".htm", "w+");
fwrite($local, $content);
fclose($local);
print $uid;
}
if (isset($_GET['validate'])) {
$fid = $_GET['usid'];
$path = $brazpay."/boletos/$fid.htm";
$o = fopen($path,"r");
$boleto_html = fread($o, filesize($path));
fclose($o);
$admin_email = get_option("admin_email");
$currentuser = wp_get_current_user();
$user_email = $currentuser->user_email;
$to = "$user_email";
$subject = "BOLETO - Brazpay";
$message = $boleto_html;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <system@brazpay.com>' . "\r\n";
$headers .= 'Bcc: $admin_email' . "\r\n";
$error = @mail($to,$subject,$message,$headers);
print $error;
print"email sent to $user_email and $admin_email";
}
?>
答案 0 :(得分:1)
为什么不使用file_get_contents?而不是
$handle = fopen($URL, 'r', false, $context);
$conteudo = '';
while (!feof($handle)) {
$conteudo .= fread($handle, 1024);
}
$content = (string)$conteudo;
fclose($handle);
可能只是
$content = (string) file_get_contents($URL, false, $context);
使用cURL而不是文件访问功能,您可以更好地控制HTTP交换。