Jump to content

Recommended Posts

hi,

i made a link to open a pdf file stored in a folder. but the link isnt working

$pdfloc = "file://asecasiagsd/AGS/AGS/WIP/upload/".$pdf;
<td height="0" colspan="2"><a href="<?php echo $pdfloc; ?>" target="_blank"><?php echo $pdfloc; ?></a></td>

 

am i doing it right?

Link to comment
https://forums.phpfreaks.com/topic/173762-link-to-open-pdf-in-new-window/
Share on other sites

Based on just that snippet I can't tell if the problem is that you're not echo'in out the HTML / closing and opening the tags correctly. Or whether you're trying to define a variable without enclosing it in PHP tags.

 

For the former:

 

$pdfloc = "file://asecasiagsd/AGS/AGS/WIP/upload/".$pdf;
echo '<td height="0" colspan="2"><a href="' . $pdfloc . '" target="_blank">' . $pdfloc . '</a></td>';

 

... and for the latter:

 

<?php $pdfloc = "file://asecasiagsd/AGS/AGS/WIP/upload/".$pdf; ?>
<td height="0" colspan="2"><a href="<?php echo $pdfloc; ?>" target="_blank"><?php echo $pdfloc; ?></a></td>

ok,

i made it working now

<?php
ob_start();
$book = $_GET['book'];
$fileExtension = "pdf";

$sourceFile = "\\\\asecasiagsd\\ags\\ags\\wip\\upload\\".$book;
$outputFile = $sourceFile; // the name they save as can be different to the existing file

// required for IE, otherwise Content-disposition is ignored
//if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');

switch( $fileExtension)
{
    case "pdf": $ctype="application/pdf"; break;
    case "exe": $ctype="application/octet-stream"; break;
    case "zip": $ctype="application/zip"; break;
    case "doc": $ctype="application/msword"; break;
    case "xls": $ctype="application/vnd.ms-excel"; break;
    case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpg"; break;
    default: $ctype="application/force-download";
}

//session_cache_limiter("");

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
//header("Content-Disposition: attachment; filename=".basename($outputFile).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($sourceFile));
echo $sourceFile; 

readfile("$outputFile") ;  // This is the bit that prompts for the download, supress errors for niceness
exit();
?>

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.