首页 > 解决方案 > 需要来自 URL 的 PHP 文件

问题描述

当我在 PHP 上编写代码时,我需要 require 或导入 .PHP 文件,其中包含我需要的类和函数。例如`

<?php require("ffmpeg.php"); ?>

我是否需要 PHP 文件,我在根目录中没有该文件,但它存储在网站上,例如`

<?php require("http://example.com/ffmpeg.php"); ?>

如果是真的,请帮我解答这个问题。

标签: phprequire

解决方案


使用 file_get_contents 然后您需要将内容写入文件,或者您可以直接使用 eval 执行。

 //option 1 save to file
$contents = file_get_contents("http://example.com/ffmpeg.php");
file_put_content("yourphpfilename.php", $contents);

//option 2 get and execute
$contents = file_get_contents("http://example.com/ffmpeg.php");
eval($contents);

推荐阅读