bepster
bepster

Reputation: 93

PHP Image Link to Open PDF

Evening All

I am currently writing some PHP it loops through an array and returns the results in a table.

One of the columns I would like to be titled "Drawing" this column will contain a PDF icon if a PDF file exists in a server location, if no file exists with a relevant name then it will be blank.

So far so good I have the above working!!

However when I click on the PDF icon nothing happens....

If I do a right click save target as I can save the PDF but this is not the behavior I would like to happen, I would like the PDF to open up in the browser and preview.

I am quite new to PHP programming so feel free to let me know if I'm going about this the wrong way!

Here is my PHP as of current:

<?php
// RETURN RESULTS
$results = sqlsrv_query( $conn, $searchquery, $params );

if( $results === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $results, SQLSRV_FETCH_ASSOC) ) {
// BUILD FILE LOCATION NAME
    $filename = "\\\\domainname\\dfsr\\sharename\\foldername\\foldername\\foldername\\" . TRIM(strtolower($row['product'])) . ".pdf";

// CHECK IF FILE EXISTS OR NOT AND CREATE PDF ICON VARIABLE
    if (file_exists($filename)) {
        $pdf_drawing = "<a href=".$filename."> <img src=" . '"images/pdf_icon.png"' . " /> </a>";
    } else {
        $pdf_drawing = "";
    };
      echo "<tr>
//CREATE TABLE DATA PER ROW
                <td>".$row['warehouse']."</td>
                <td>".$row['product']."</td>
                <td>".$row['analysis_b']."</td>
                <td>".$row['long_description']."</td>
                <td>".$row['drawing_number']."</td>
                <td> " . $pdf_drawing . "</td>
            </tr>";
}
?>

Any help is much appreciated!

Thanks,

Bepster

Upvotes: 1

Views: 181

Answers (2)

BusinessFawn
BusinessFawn

Reputation: 301

Can you try assigning a target attribute?

for instance:

<a href=".$filename"target="_self"><img src="../../img.png"></a>

Upvotes: 0

bepster
bepster

Reputation: 93

Internet Explorer automatically blocks all UNC paths unless the site is added into the intranet list

Upvotes: 1

Related Questions