Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert php variable in a href

Tags:

php

href

I am planning to insert a PHP variable which holds the directory path for a file stored on my Windows machine. How can I include this variable in the a href tag inside my php script such that when the user clicks this link it should be redirected to that particular folder and file.

For ex: $folder_path = 'C:\docs\test\file1.txt';

Right now I have tried some different ways but with no success. I have also did some research on internet, but alas could not find a proper answer.

If any one has an idea would be thankful if it can be shared. Thanks

like image 272
125369 Avatar asked Nov 24 '11 11:11

125369


2 Answers

echo '<a href="' . $folder_path . '">Link text</a>';

Please note that you must use the path relative to your domain and, if the folder path is outside the public htdocs directory, it will not work.

EDIT: maybe i misreaded the question; you have a file on your pc and want to insert the path on the html page, and then send it to the server?

like image 52
Strae Avatar answered Sep 24 '22 06:09

Strae


You could try:

<a href="<?php echo $directory ?>">The link to the file</a>

Or for PHP 5.4+ (<?= is the PHP short echo tag):

<a href="<?= $directory ?>">The link to the file</a>

But your path is relative to the server, don't forget that.

like image 30
LostMohican Avatar answered Sep 26 '22 06:09

LostMohican