php - 需要来自 URL 的 PHP 文件
问题描述
当我在 PHP 上编写代码时,我需要 require 或导入 .PHP 文件,其中包含我需要的类和函数。例如`
<?php require("ffmpeg.php"); ?>
我是否需要 PHP 文件,我在根目录中没有该文件,但它存储在网站上,例如`
<?php require("http://example.com/ffmpeg.php"); ?>
如果是真的,请帮我解答这个问题。
解决方案
使用 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);
推荐阅读
- d3.js - d3js 甘特图,顶部有日期/时间刻度,当天蓝线
- python - https请求中的签名是如何加密的?
- arrays - Google App Script将单个元素分解为具有多个元素的一维数组
- java - SwingNode 在 macOS 上使用 JDK 11.0.6(和其他)显示空白窗口,但不使用 JDK 11.0.2。有解决方法吗?
- terraform - Terraform:有条件地安装 TF 模块
- android - 由于我的应用程序的后台通知导致三星设备上经常崩溃的消息
- android - 在 textview 中设置一些文本粗体,但不是全部
- php - POST 和 GET 在 Postmen 中有效,但 PUT 和 DELETE 无效
- c# - 在 ItemTemplate 字段中使用 C# 转换为 PDF 时出现问题
- python-3.x - 如何在 python 3 中创建一个简单的 HTTP 网络服务器,用生成的内容响应 GET 请求?