Created
October 15, 2023 19:20
-
-
Save Atefnouri/0bf00e1ecbd1afed782a8eac918754bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
include('../dbconnect.php'); | |
$numero_retour = mysqli_query($connect, "SELECT max(`num_ordre_arrivee`) as num_ord FROM `arrivee` WHERE 1"); | |
$return = mysqli_fetch_array($numero_retour); | |
$retour = $return['num_ord'] + 1; | |
$non_extension = 0; | |
$extension = 0; | |
$pdf_extension = 0; | |
$png_extension = 0; | |
//debug function | |
function writeStringToFile($message,$messageValue) { | |
// Open the file for writing (creates the file if it doesn't exist) | |
$filePath = "../pdf/debug.txt"; | |
$content = $message.strval($messageValue); | |
//$file = fopen('debug.txt', 'w'); | |
$file = fopen($filePath, 'a'); | |
if ($file) { | |
// Write the string to the file | |
fwrite($file, $content . "\n"); | |
// Close the file | |
fclose($file); | |
} | |
} | |
if (isset($_FILES['files'])) { | |
$countfiles = count($_FILES['files']['name']); | |
if ($countfiles > 0) { | |
for ($index = 0; $index < $countfiles; $index++) { | |
$filename = $_FILES['files']['name'][$index]; | |
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); | |
$test_ext = '/' . $ext . '/'; | |
if ($test_ext == '/jpeg/' or $test_ext == '/jpg/') { | |
$extension = $extension + 1; | |
writeStringToFile("the file is jpeg ",$extension); | |
} elseif($test_ext == '/png/') { | |
$png_extension++; | |
writeStringToFile("png file detected ",$png_extension); | |
} elseif($test_ext == '/pdf/' or $test_ext == '/PDF/') { | |
$pdf_extension = $pdf_extension + 1; | |
writeStringToFile("pdf_extension ",$pdf_extension); | |
}else { | |
$non_extension = $non_extension + 1; | |
writeStringToFile("file with unspported extenoin ",$non_extension); | |
//writeStringToFile(" $non_extension " + strval($non_extension)); | |
} | |
} | |
} | |
} | |
//upload when jpeg is available | |
if (isset($_FILES['files']) && $non_extension == 0 && $pdf_extension == 0 && $png_extension == 0) { | |
writeStringToFile("message:","conversion is working on jpeg"); | |
$countfiles = count($_FILES['files']['name']); | |
require('fpdf/fpdf.php'); | |
class PDF extends FPDF | |
{ | |
function Header() | |
{ | |
} | |
function Footer() | |
{ | |
$this->SetY(-15); | |
$this->SetFont('Arial', 'I', 8); | |
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); | |
} | |
} | |
$pdf = new PDF(); | |
if ($countfiles > 0) { | |
for ($index = 0; $index < $countfiles; $index++) { | |
$filename = $_FILES['files']['name'][$index]; | |
$upload_location = "image/"; | |
$path = $upload_location . $filename; | |
move_uploaded_file($_FILES['files']['tmp_name'][$index], $path); | |
$pdf->AliasNbPages(); | |
$pdf->AddPage(); | |
$pdf->SetFont('Times', '', 12); | |
$filename = $_FILES['files']['name'][$index]; | |
$upload_location = "image/"; | |
$path = $upload_location . $filename; | |
$pdf->Image($path . "", 5, 6, 200, 260, 'JPEG'); | |
unlink($path); | |
} | |
$pdf->Output("../pdf/" . $_SESSION['upload_img'] . ".pdf", "F"); | |
} | |
} | |
//upload when png | |
if (isset($_FILES['files']) && $non_extension == 0 && $pdf_extension == 0 && $png_extension == 1 ) { | |
writeStringToFile("message:","conversion is working on png"); | |
$countfiles = count($_FILES['files']['name']); | |
require('fpdf/fpdf.php'); | |
class PDF extends FPDF | |
{ | |
function Header() | |
{ | |
} | |
function Footer() | |
{ | |
$this->SetY(-15); | |
$this->SetFont('Arial', 'I', 8); | |
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); | |
} | |
} | |
$pdf = new PDF(); | |
if ($countfiles > 0) { | |
for ($index = 0; $index < $countfiles; $index++) { | |
$filename = $_FILES['files']['name'][$index]; | |
$upload_location = "image/"; | |
$path = $upload_location . $filename; | |
move_uploaded_file($_FILES['files']['tmp_name'][$index], $path); | |
$pdf->AliasNbPages(); | |
$pdf->AddPage(); | |
$pdf->SetFont('Times', '', 12); | |
$filename = $_FILES['files']['name'][$index]; | |
$upload_location = "image/"; | |
$path = $upload_location . $filename; | |
$pdf->Image($path . "", 5, 6, 200, 260, 'PNG'); | |
unlink($path); | |
} | |
$pdf->Output("../pdf/" . $_SESSION['upload_img'] . ".pdf", "F"); | |
} | |
} | |
//upload when pdf is available | |
if ( isset($_FILES['files']) && $pdf_extension == 1) { | |
writeStringToFile("targetFile ","pdf is working "); | |
$countfiles = count($_FILES['files']['name']); | |
for ($index = 0; $index < $countfiles; $index++) { | |
$filename = $_FILES['files']['name'][$index]; | |
$upload_location = "../pdf/"; | |
$path = $upload_location . $_SESSION['upload_img'] . ".pdf"; | |
writeStringToFile("filename ",$filename); | |
move_uploaded_file($_FILES['files']['tmp_name'][$index], $path); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment