Getting the Uniform Resource Locator right

Gurus,
Please, could you help me with this:

My code works perfectly well
<?pdf
...
  $pdfcode = $pdf->output();
  $dir = 'dokument';
  //save the file
  if (!file_exists($dir))    {   mkdir ($dir,0777);  }
  $fname = tempnam($dir.'/','pdftest').'.pdf';
  $fp = fopen($fname,'w');
  fwrite($fp,$pdfcode);
  fclose($fp);

until I create a url for a link:

echo '<html>
<head>
</head>
<body>
<a href="'.$fname.'">click here</a>.
</body>
</html>';
?>
The $fname comes out in format like
/customers/4/8/3/whatever.com/httpd.www/admin/dokument/pdftesteMRNMS.pdf, where  /customers/4/8/3/whatever.com/httpd.www/ is the absolute address for this server.
The url becomes http://whatever.com/customers/4/8/3/whatever.com/httpd.www/admin/dokument/pdftesteMRNMS.pdf which the browser doesn't understand.

Could you, please, help me create a working url.
Lennart EricsonAmateurAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
I doubt if you can indict the IE browser completely.  Good coding practices will result in programming that works cross-browsers.

If $fname has several levels of directories, you might want to use basename() to retrieve the things you want to keep.
http://php.net/manual/en/function.basename.php

It is the same as end(explode(DIRECTORY_SEPARATOR, $fname));
http://php.net/manual/en/function.explode.php
http://php.net/manual/en/function.end.php
0
 
Ray PaseurCommented:
Probably you want the URL to be something like this, maybe?

http://whatever.com/dokument/pdftesteMRNMS.pdf 

If so you might try using $_SERVER["HTTP_HOST"] . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . 'pdftesteMRNMS.pdf'
0
 
Lennart EricsonAmateurAuthor Commented:
Ray,
Thanks.
My problem is this:
The variable "$fname" is output "/customers/4/8/3/whatever.com/httpd.www/admin/dokument/pdftesteMRNMS.pdf" and I would like to have it just "pdftesteMRNMS.pdf". I. e. I'd like to strip off  "/customers/4/8/3/whatever.com/httpd.www/admin/dokument/"
How can that be achieved?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Lennart EricsonAmateurAuthor Commented:
This was IE browser problem. Solution was simple: Close browser and restart.
0
 
Lennart EricsonAmateurAuthor Commented:
Ray,
Your answeer to my question is correct and accepted. Thank you.
lericson
0
 
Ray PaseurCommented:
Glad to help -- thanks for the points and best of luck with your project! ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.