在href中插入php变量 [英] Insert php variable in a href

查看:84
本文介绍了在href中插入php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算插入一个PHP变量,该变量保存Windows计算机上存储的文件的目录路径.我如何在我的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.

例如:$folder_path = 'C:\docs\test\file1.txt';

现在,我尝试了一些不同的方法,但没有成功.我也在互联网上做了一些研究,但是but找不到合适的答案.

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

推荐答案

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

请注意,您必须使用相对于您的域的路径,并且,如果文件夹路径不在公共htdocs目录中,则该路径将无效.

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.

也许我读错了问题;您的PC上有一个文件,想要在html页面上插入路径,然后将其发送到服务器?

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?

这篇关于在href中插入php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆