Create a URL to open a PDF file - PHP

Asked

Viewed 700 times

0

Good afternoon to all,

I’m developing a code for searching keywords in the database. So far, ok! However, I am skating while trying to open the file referring to the result I found.

This is the keyword search code:

<?php

// Include conexão com o bd.
include 'conexaoBD/conexao.php';
include 'teste.php';


$btn     = $_POST['btn'];
$p_chave = $_POST['palavra'];

if(isset($btn)){
    $busca = $p_chave;

    if($busca == null or $busca == " "){

        echo '<center><b>Digite a palavra-chave para pesquisar!</b></center>';

    } else {

        $busca_div = explode(' ',$busca);
        $quant     = count($busca_div);
        $exibe_id  = array("");

        for($i=0; $i<$quant; $i++){
            $pesquisa = $busca_div[$i];

            $_sql       = "SELECT * FROM conteudo_dcm WHERE DCM_conteudo LIKE '%$pesquisa%';";
            $sql        = mysqli_query($conn,$_sql);

            $quant_cmps = mysqli_num_rows($sql);

            if($quant_cmps == 0){

                echo '<center><b>Nenhum resultado obtido!</b></center>';

            } else {

                while($linha = mysqli_fetch_array($sql)){
                    $id       = $linha['DCM_id'];
                    $nome     = $linha['DCM_nome'];
                    $conteudo = $linha['DCM_conteudo'];

                    $_href = $_folder.$_DS.$nome; // Variável definida no arquivo "teste.php"

                    if(!array_search($id,$exibe_id)){
                        echo '<a href="<?php $_href; ?>">'.$nome.'</a>'."<br><br>".
                             substr($conteudo, 0, 600)."<b> ...</b>".
                             "<br>---------------------<br>";   

                        array_push($exibe_id,$id);
                    }
                }
            }
        }
    }
}
?>

My question is mainly on this part of the code (like mounting the url refente to the file I saved on the server).

echo '<a href="<?php $_href; ?>">'.$nome.'</a>'."<br><br>".
                                 substr($conteudo, 0, 600)."<b> ...</b>".
                                 "<br>---------------------<br>";   
  • I’m guessing that your variable $folder is filled with the directory within the operating system where you write the files, is that right? If this is the case you have to translate this path to the route that leads to the file by entering http. If you can put the section that creates this variable I can try to help more.

  • Yes @Diegomartins, the $Folder variable is the directory where the Arq. are stored. Follow the passage that creates this variable: "$_DS = DIRECTORY_SEPARATOR; $_Folder = dirname(DIR).$_DS.'03-OCR-Pdflib'. $_DS.'arqs_Teste'; "

1 answer

1

When a PDF file opens in a browser, the first page of the PDF file will be shown by default. You can add a string in the HTML link so that a PDF file opens and jumps to a specified page or sets the destination. To use one of these two methods, do the following:

Open a PDF file on a specific page To direct an HTML link to a page in a specific PDF file, add #page= [page number] at the end of the link URL.

For example, this HTML tag opens page 4 of a PDF file called Myfile.pdf:

Note: If you use UNC server paths ( folder name_do_server) in a link, set the link to open a destination defined using the procedure in the next section. If you use Urls containing local hard drive addresses (c: folder), it is not possible to link to page numbers or to defined destinations. With Adobe Acrobat 7.0 products, a link to a page number only works if you use HTTP or HTTPS locations. UNC server locations will only work if you use the defined destination method described in the next section of this document.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.