[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting the Uniform Resource Locator right

Posted on 2011-10-09
6
Medium Priority
?
322 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:Lennart Ericson
  • 3
  • 3
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36939325
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
 

Author Comment

by:Lennart Ericson
ID: 36939371
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
 

Author Comment

by:Lennart Ericson
ID: 36939492
This was IE browser problem. Solution was simple: Close browser and restart.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 36940340
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
 

Author Comment

by:Lennart Ericson
ID: 36941008
Ray,
Your answeer to my question is correct and accepted. Thank you.
lericson
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36942013
Glad to help -- thanks for the points and best of luck with your project! ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question