こんにちは、私はpdfファイルを変更してサーバに保存しようとしていますが、このエラーが続いています。それの原因。FPDFエラー:一部のデータは既に出力されています - PHPスクリプト
<?php
ob_start();
include_once '../db_connect.php';
$JOUR = date('d');
$MOIS = date('m');
$ANNEE = date('Y');
$TIME = date("h:i:s");
$date = $ANNEE . "-" . $MOIS . "-" . $JOUR . " " . $TIME;
// titre rapport
$rapFR = $_POST['rapportFR'];
$rapUK = $_POST['rapportUK'];
$categ = $_POST['categ'];
$rapportFR = str_replace("/", "-", $rapFR);
$rapportUK = str_replace("/", "-", $rapUK);
$cherche = array('é', 'è', 'ê', 'ç', 'à', 'â', 'û', 'ù', '/');
$remplace = array('e', 'e', 'e', 'c', 'a', 'a', 'u', 'u', '-');
//noms pour les fichiers upload
$uploadFR = str_replace($cherche, $remplace, $rapFR);
$uploadUK = str_replace($cherche, $remplace, $rapUK);
//echo $uploadFR;
//message optionnel
$messageAdditionel = $_POST['elm1'];
$sql = "INSERT INTO rapport(categorie,date,titreUK,titreFR,nomfichier) VALUES ('$categ', '$date', '$rapportUK', '$rapportFR', '$rapportFR');";
$req = mysqli_query($mysqli, $sql) or die('Erreur SQL !<br/>' . $sql . '<br/>' . mysqli_error($mysqli));
$sql2 = "SELECT * FROM rapport ORDER BY idr DESC;";
$req2 = mysqli_query($mysqli, $sql2) or die('Erreur SQL !<br/>' . $sql2 . '<br/>' . mysqli_error($mysqli));
$data = mysqli_fetch_array($req2);
$idr = $data['idr'];
$sqlIdRap = "SELECT * FROM rapport ORDER BY idr DESC LIMIT 1;";
$reqIdRap = mysqli_query($mysqli, $sqlIdRap) or die('Erreur SQL !<br/>' . $sqlIdRap . '<br/>' . mysqli_error($mysqli));
if ($dataIdRap = mysqli_fetch_array($reqIdRap)) {
$idRapport = $data['idr'];
}
$dirFR = '../articles/FR/' . $idRapport . '-' . $uploadFR;
$dirUK = '../articles/UK/' . $idRapport . '-' . $uploadUK . '/';
if ($dataIdRap = mysqli_fetch_array($reqIdRap)) {
$idRapport = $data['idr'];
}
$dirFR = '../articles/FR/' . $idRapport . '-' . $uploadFR;
$dirUK = '../articles/UK/' . $idRapport . '-' . $uploadUK . '/';
$oldmask = umask(0);
if (!file_exists($dirFR)) {
mkdir($dirFR, 777, true);
}
if (!file_exists($dirUK)) {
mkdir($dirUK, 777, true);
}
umask($oldmask);
$count = 0;
setlocale(LC_TIME, 'en_US.UTF-8', 'en');
$dateUK = strftime('%A %d %B %Y');
$dateUK = mb_convert_encoding($dateUK, 'UTF-8', 'ISO-8859-1');
setlocale(LC_TIME, 'fr_FR.utf8', 'fra');
$dateFR = strftime('%A %d %B %Y');
$dateFR = mb_convert_encoding($dateFR, 'UTF-8', 'ISO-8859-1');
$monRapportFR = $dirFR . "/$uploadFR.php"; // or .php
//recuperation du fichier PDF
$pdfFR = $_FILES['rapportFR']['name'];
$fh = fopen($monRapportFR, 'w'); // or die("error");
$corpsFR = "$entete";
$corpsFR .= "</head><body>";
$extention = pathinfo($pdfFR, PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES['rapportFR']['tmp_name'], $dirFR . "/" . $pdfFR)) {
}
$dirFinal = $dirFR . $pdfFR;
// if($option_impression==true){
$corpsFR .= "<embed src='$pdfFR' style='float:left;width:100%;height:100%'>";
// }
$corpsFR .= "</body> </html>";
fwrite($fh, $corpsFR);
$monRapportUK = $dirUK . "/$uploadUK.php"; // or .php
//recuperation du fichier PDF
$pdfUK = $_FILES['rapportUK']['name'];
//echo $pdfUK;
$fh = fopen($monRapportUK, 'w'); // or die("error");
$corpsUK = "$entete";
$corpsUK .= "</head><body>";
$extention = pathinfo($pdfUK, PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES['rapportUK']['tmp_name'], $dirUK . "/" . $pdfUK)) {
}
$dirFinal = $dirUK . $pdfUK;
// if($option_impression==true){
$corpsUK .= "<embed src='$pdfUK' style='float:left;width:100%;height:100%'>";
// }
$corpsUK .= "</body> </html>";
fwrite($fh, $corpsUK);
require_once '../swiftmailer/lib/swift_required.php';
$sql4 = "SELECT * FROM appartenir, groupe, contact WHERE groupe.idg = appartenir.idg AND appartenir.idc = contact.idc AND appartenir.idg = $categ AND isDeleted = 0 ;";
$req4 = mysqli_query($mysqli, $sql4) or die('Erreur SQL !<br/>' . $sql4 . '<br/>' . mysqli_error($mysqli));
//indicateurs listes fr/uk
$nbrFR = 0;
$nbrUK = 0;
$ajoutSQL = "";
//liste des contacts fr/uk
$destinataireFR = array();
$destinataireUK = array();
while ($data4 = mysqli_fetch_array($req4)) {
$idc = $data4['idc'];
$emailC = $data4['mail'];
$cle = $idr . $idc . bin2hex(openssl_random_pseudo_bytes(8));
$langue = $data4['langue'];
//fin du lien de rapport
$data = array('idr' => $idr,
'cle' => $cle);
$url = "?" . http_build_query($data);
$lienFR = "127.0.0.1/newsletter/articles/FR/" . $idRapport ."-". $uploadFR . "/" . $uploadFR . ".php" . $url;
$lienUK = "127.0.0.1/newsletter/articles/UK/" . $idRapport ."-". $uploadUK . "/" . $uploadUK . ".php" . $url;
if($langue=="FR"){
$destinataireFR[$nbrFR] = array(
"mail" => $emailC,
"lien" => $lienFR
);
$nbrFR++;
}else{
$destinataireUK[$nbrUK] = array(
"mail" => $emailC,
"lien" => $lienUK
);
$nbrUK++;
}
$ajoutSQL = $ajoutSQL ."('$cle',$idr,$idc),";
///// ajouter message additionel //////
$messageAdditionel;
}
//suppression de la derniere virgule
$ajoutSQL = rtrim($ajoutSQL,",");
//Ajout cle dans Code
$sql5 = "INSERT INTO code(cle,idr,idc) VALUES $ajoutSQL;";
$req5 = mysqli_query($mysqli, $sql5) or die('Erreur SQL !<br/>' . $sql5 . '<br/>' . mysqli_error($mysqli));
// SMTP
require '../smtp/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->IsSMTP();
//paramètres et contenu du mail
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Username = "test";
$mail->Password= "test";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
$mail->From = "[email protected]";
$mail->IsHTML(true);
require_once('../fpdf17/fpdf.php');
require_once('../FPDI/fpdi.php');
$pdf = new FPDI();
foreach($destinataireFR as $destinataireFR){
$mail->Body = "<p style='font-family:Calibri'>Bonjour,<br/><br/><a href='$destinataireFR[lien]' style='font-size:1.1em'>Cliquez ici</a> pour ouvrir le fichier <b>$rapportFR</b>.<br/><br/>Cordialement,<br/><br/><b style='color:#4271BE'>L'Equipe Horizon Soft Commodities</b><br/>01.49.89.46.16<br/><a href='mailto:[email protected]'>[email protected]</a><br/><br/><br/><p style='font-size:0.8em'>Si vous souhaitez vous désinscrire et ne plus recevoir ces messages, <a href='mailto:[email protected] &subject=Desinscription'>cliquez ici</a>.</p><br/>$messageAdditionel</p>";
$mail->Subject = "$rapportFR";
$mail->AddAddress("$destinataireFR[mail]");
if($categ == 27)
{
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile($dirFR . "/" . $pdfFR);
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 0,0 with a width of 300 mm(pour un centrage comme reel)
$pdf->useTemplate($tplIdx, 0, 0, 300);
$pdf->SetXY(70, 70);
$pdf->Write(0, "test");
$pdf->SetXY(100, 80);
$pdf->Write(0, "test");
}
if ($mail->Send()){
// echo "success<br/>";
}else{
// echo "fail : ". $mail->ErrorInfo . "<br/>";
}
$mail->ClearAddresses();
}
$pdf->Output();
ob_end_flush();
?>
db_connect.php
<?php
include_once 'sql-config.php'; // file contening db credentials
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$mysqli->query("SET CHARACTER SET utf8");
//message d'erreur en cas d'échec
if ($mysqli->connect_errno) {
echo "Echec lors de la connexion à MySQL : (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
誰かが、これはどこから来るん知っている:ここで
は、PHPスクリプトですか?
我々は完全なPHPスクリプトを見ることができます。問題は終わりに$ pdf-> output()コールと思われます。 FPDFは何かが既に送信されたため、ブラウザに出力を送信できません。開いている<?phpタグの前に空白行のような単純なものがあります。 – SheppardDigital
実際には私のスクリプトは300行以上長いですが、私はそれをまだ投稿する必要がありますか? <?phpタグの前に空白行がありません。末尾にはありません。 – DeveloppeurDuTurfu
<?phpタグの前に、データを出力しているもの、echoコマンド、空行を見てください。 – SheppardDigital