Jump to content

Best way to store a link to pdf in database?


anton_1

Recommended Posts

Hey guys!,

 

Any help is greatly appreciated! what i want to do is store a link to a pdf file which will open the file when clicked.

 

just now when clicked will only open the file name but not with the extension .pdf?

 

 

Thanks!

Link to comment
Share on other sites

Hey guys!,

 

Any help is greatly appreciated! what i want to do is store a link to a pdf file which will open the file when clicked.

 

just now when clicked will only open the file name but not with the extension .pdf?

 

 

Thanks!

 

Hello,

 

Are you uploading the file? If so, can you post how you are?

 

Sounds like you are saving the filename but not the extension..

Link to comment
Share on other sites

thanks for your reply mate, yes that exactly correct im saving the file name as filename.pdf and the file is stored within the server folder :)

 

but when I select all form database and click on it, it only goes to http://localhost/pagename/filename                  whithout the .pdf

Do you have any code that you can post? It's a bit hard to help without seeing what you are actually doing at the moment..

Link to comment
Share on other sites

Yeah mate :)

 

 

this retrieves the file and outputs it.

 

after I have clicked the link and it displays in the url. if I add .pdf onto the end it does display the pdf.  So even if there was a way to put  . ".pdf" after it or something?

 

 

thanks again!

 

 

<?php

 

function checkValues($value)

{

// Use this function on all those values where you want to check for both sql injection and cross site scripting

//Trim the value

$value = trim($value);

 

// Stripslashes

if (get_magic_quotes_gpc()) {

$value = stripslashes($value);

}

 

// Convert all <, > etc. to normal html and then strip these

$value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));

 

// Strip HTML Tags

$value = strip_tags($value);

 

// Quote the value

$value = mysql_real_escape_string($value);

return $value;

 

}

 

include("dbcon.php");

 

$rec = checkValues($_REQUEST['val']);

 

 

 

//get table contents

 

 

if($rec)

 

{

 

$sql = "select * from questions where Question like '%$rec%'";

 

}

 

else

 

{

 

$sql = "select * from questions";

 

}

 

 

 

$rsd = mysql_query($sql);

 

$total =  mysql_num_rows($rsd);

 

?>

 

 

 

<?php

 

while ($rows = mysql_fetch_assoc($rsd))

 

{?>

 

 

<div class="each_rec"><a href="<?php echo $rows['Question'];?>" target="_blank"><?php echo $rows['HelpDocument'];?></a></div>

 

<?php

 

}

 

if($total==0){ echo '<div class="no-rec">No Record Found !</div>';}?>

 

Link to comment
Share on other sites

Next time wrap code in code tags, much easier to read. I was thinking more along the lines of the code you use to upload the file but ultimately save it in your table as that is the part thats missing.

 

If you wanted to amend .pdf you could:

 

<a href="<?php echo $rows['Question'].'.pdf'; ?>" target="_blank">

 

Should work. Although that then forces you to have each file a PDF.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.