普通网友 2016-04-28 02:59
浏览 22

如何将参数作为GET方法传递给脚本? [重复]

This question already has an answer here:

I have this folder-structure:

\out
    \MakeAvatar.php
oot
    \include
        \Calculator.php
    \img
        \avatar

What's MakeAvatar.php? That's a script which gets a parameter (like id) and makes a avatar based on that parameter. Now I need to pass a argument ($id) from Calculator.php to MakeAvatar.php. How can I do that?

Here is my code:

$_GET['id'] = $id; // passing
file_put_contents("../img/avatar/".$id.".jpg", file_get_contents("../out/MakeAvatar.php"));

But it doesn't work. I mean the result is a unknown-image (unclear).

enter image description here

When I open that image by a editor, it is containing the content of MakeAvatar.php (all its codes). So it seems the problem is passing.


Note1: If I put MakeAvatar.php into root and pass that argument like this then if works:

... file_get_contents("http://example.com/MakeAvatar.php?id=$id")

But as you see MakeAatar.php is out of root and I cannot use http. So how can I pass an argument without http?

</div>
  • 写回答

2条回答 默认 最新

  • dongqin8652 2016-04-28 03:06
    关注

    Your file_get_contents is actually reading the file contents, rather than executing it.

    You'll either have to include your file from Calculator.php or expose it to the HTTP server and do a local http request (eg. like file_get_contents('http://localhost/path/to/your/MakeAvatar.php') )

    I'd recommend wrapping your important logic in the MakeAvatar file into a function, then includeing it and executing the function.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?