PHP中的网页文件快捷方式

发布于 11-14 01:37 字数 593 浏览 4 评论 0原文

我希望我知道如何创建一个作为网页主要访问权限的文件。我正在使用 PHP 来执行此操作。我想到了以下事情:

function crearArchivoUrl($url){
        $archivo=str_replace(array("http://", "https://", "mailto://", "ftp://"), "", $url);
        $archivo=str_replace(array("/"), "-", $archivo);
        $this->checkNombreDestino($archivo);
        $contenido="[InternetShortcut]\r\nURL=".$url."\r\n";
        $fp = fopen($archivo, 'w');
        chmod($archivo, 0644);
        fwrite($fp, $contenido);
        fclose($fp);
    }

但是当我测试它(通过双击它)时,我没有跳转浏览器。

谁能告诉我如何制作网页快捷方式的文件?

感谢您的帮助。

问候!

I wish I knew how to make a file that is a principal access to a web page. I'm using PHP to do this. It occurred to me the following:

function crearArchivoUrl($url){
        $archivo=str_replace(array("http://", "https://", "mailto://", "ftp://"), "", $url);
        $archivo=str_replace(array("/"), "-", $archivo);
        $this->checkNombreDestino($archivo);
        $contenido="[InternetShortcut]\r\nURL=".$url."\r\n";
        $fp = fopen($archivo, 'w');
        chmod($archivo, 0644);
        fwrite($fp, $contenido);
        fclose($fp);
    }

But when I test it (by double-clicking on it) I did not jump the browser.

Anybody can tell me how to make files that are shortcuts to web pages?

Thanks for the help.

Greetings!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天暗了我发光2024-11-21 01:37:17

我的代码是正确的,我所需要的只是文件扩展名应该是 .url,即 my-web-shortcut.url

感谢您所做的一切。

问候!

My code was correct, all I needed was that the file extension should be .url, ie, my-web-shortcut.url

Thanks for everything.

Greetings!

笑梦风尘2024-11-21 01:37:17

仅当您安装了 PHP 解释器并且将网络服务器配置为运行您的 PHP 文件时,您的 PHP 才会被执行。如果您将此文件分发到未配置的计算机,它永远不会作为 PHP 代码执行,因此永远不会按您的预期运行。

如果您在正确配置的网络服务器上运行此脚本,请考虑使用 header("Location:") 将用户重定向到新页面。

Your PHP will only be executed if you have a PHP interpreter installed, and if the webserver is configured to run your PHP file. If you distribute this file to unconfigured computers, it will never be executed as PHP code, and will therefore never run as you expect.

If you are running this script on a webserver that is properly configured, consider using header("Location: <URL>") to redirect the user to the new page.

实际上,您正在读取一个文件,并将其写入另一个文件。这样做不会向网络浏览器发送任何内容。

第一种方法是发送 标头 位置来重定向浏览器。请参阅手册中的示例以了解如何使用它。

另一种方法是使用 echo 读取文件内容并打印它或任何其他打印命令。

Actually, you are reading a file, and writing it to another file. Doing that sends nothing to the web browser.

A first approach would be to send a header Location to redirect the broswer. See examples in the manual to know how to use it.

Another approach would be to read the file contents, and to print it, using echo or any other printing command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文