Url of word document
Moderator: General Moderators
Url of word document
I have word document "mydoc.doc" sitting in the directory inside my public_html.
My php script is running in the different directiry.
I would like my scipt to show link that when user click on it will open "mydoc.doc". How do i get URL of "mydoc.doc"?
My php script is running in the different directiry.
I would like my scipt to show link that when user click on it will open "mydoc.doc". How do i get URL of "mydoc.doc"?
Re: Url of word document
did you upload it? what directory did you browse to when you uploaded it?
Re: Url of word document
Yes i did.
It is here /var/www/username/directory1/directory2/mydoc.doc
It is here /var/www/username/directory1/directory2/mydoc.doc
Re: Url of word document
then assuming the root of the website is at /var/www/username/ the link should be:
One way you can make sure is to run this script on your site:
(see http://www.php.net/reserved.variables.server.php for more goodies you can get from $_SERVER)
It is good practice to put absolute links (starts off root of site, '/directory/whatever/file.html') instead of relative ones ( '/../whatever/file.html' if being called from /directory/otherdir/index.html). This way no matter where you move the file that links to the file around, it will always work.
-Greg
Code: Select all
<a href="/directory1/directory2/mydoc.doc">Open Nasty Mircosoft Word Document (LOL)</a>Code: Select all
<p>The root of this site is at: <?php echo $_SERVER['DOCUMENT_ROOT']; ?></p>It is good practice to put absolute links (starts off root of site, '/directory/whatever/file.html') instead of relative ones ( '/../whatever/file.html' if being called from /directory/otherdir/index.html). This way no matter where you move the file that links to the file around, it will always work.
-Greg
Re: Url of word document
Problem is when i have I make hyper link like this - > http://servername.com/var/www/username/ ... /mydoc.doc doesnt work
If i make it like this - > http://servername.com/username/director ... /mydoc.doc does work
Using php i can get path to the file but it always return this ->/var/www/username/directory1/directory2/mydoc.doc
If i make it like this - > http://servername.com/username/director ... /mydoc.doc does work
Using php i can get path to the file but it always return this ->/var/www/username/directory1/directory2/mydoc.doc
Re: Url of word document
Code: Select all
$strFile = '/var/www/username/directory1/directory2/mydoc.com' ; // However you are getting it...
$strFile = substr($strFile,strlen($_SERVER['DOCUMENT_ROOT']));Re: Url of word document
that definetely worked...thank you so much.but have another problem.
for simplicuty lets assume that this variable is string holding path to my file $file.
now i want to do present clickable link like this.....
And when I run it i am getting this link to be ...
current/working/directory/attached/to/$file....
how do i solve this
for simplicuty lets assume that this variable is string holding path to my file $file.
now i want to do present clickable link like this.....
Code: Select all
echo "<a href = '.$file."'>Click Here</a>";
current/working/directory/attached/to/$file....
how do i solve this
Re: Url of word document
Hi...i solved it. I had to add "http://" to my hyperlink...
thanks for help
thanks for help