Image displaying through HTTP POST method not displaying after upgrading from PHP 7.2 to PHP 8

50 Views Asked by At

So I am passing a file upload data through a form POST to a PREVIEW pdf. It used to work, but we recently changed to PHP 8 and I haven't managed to adapt it.

Here is the code block that gets the the file upload data and converts it to a bit64 in order to display it.

$imageName = $_FILES['image']['tmp_name'];

   if (!empty($imageName)) {
        $str = file_get_contents($imageName);
        $b64img = base64_encode($str);

        $imagePath = 'data:image/png;base64,' . $b64img;
    }

The Way the image is being passed through is with a form POST method.

<input type="submit" id="previewbtn" name="previewbtn" class="center-block"
                        style="width:100%; background-color:white" value="Preview" 
                        formmethod="post"
                        formaction="/incidents/incidentResult.pdf.php?PREVIEW" />

enter image description here

If more information is needed, let me know.

This is the Error it's giving me. enter image description here

1

There are 1 best solutions below

2
Madeline Kallis On BEST ANSWER

I seem to have changed code and never adapted this section. The if exists is out of syntax. I just commented it out and it seems to be working now. Thanks to all who helped me.

    // if (file_exists($imagePath)) {

        if ($reasonCode === "Overload") {
            $pdf->Image($imagePath, 15, 30, 180, 250, $imageType);
        } else {
            $pdf->Image($imagePath, 15, 85, 180, 195, $imageType);
        }
    // } else {
    //     $pdf->Cell($leftMargArr["TRAN"], $heightArr["TRAN"], "Image could not be loaded, at path:", $borderArr["ALL"], 1, 'L');
    //     $pdf->Cell($leftMargArr["TRAN"], $heightArr["TRAN"], $imagePath, $borderArr["ALL"], 1, 'L');
    // }

enter image description here