如何从PHP文件中获取值并将其插入index.php
这是我的档案:
image.php
<?php
$client_id = "xxxxxx";
$image ='https://pic.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Client-ID ' .$client_id ));
curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => $image ));
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
$newimgurl = $reply->data->link;
echo $newimgurl;index.php
<?php echo $newimgurl; ?>如果上述所有代码都位于同一个文件(index.php)中,则可以获得该值。
但我想让$newimgurl从image.php到index.php
发布于 2015-09-22 18:32:42
在你的index.php写
<?php
include_once "image.php";
echo $newimgurl;在image.php包含之后,您将可以访问image.php文件中分配的变量。
您可以阅读更多关于它的这里。
您还可以将该行echo $newimgurl;更改为return $newimgurl;,并在index.php echo include "image.php";中更改
发布于 2015-09-22 16:34:59
只需通过IMG标记的SRC属性调用php文件:
<img src="image.php" />或者使用file_get_contents通过PHP获取内容
$url = file_get_contents("image.php");编辑:
你能把"image.php“包含在index.php里面吗?
<?php
include_once("image.php")
?>https://stackoverflow.com/questions/32722142
复制相似问题