dsajkdadsa14222 2014-05-19 06:36
浏览 68

如何使用带有$ GLOBALS [“HTTP_RAW_POST_DATA”]的file_get_contents($ filename)来获取文件名?

I am using file_put_contents($filename, $jpg) to upload my jpg files to some location. How to use file_get_contents ($filename); with ($GLOBALS["HTTP_RAW_POST_DATA"])? I am trying something like $jpg = $GLOBALS["HTTP_RAW_POST_DATA"]; $img = $_GET["img"]; $filename = "applicantsPhotos/applicantPhoto". mktime(). ".jpg"; file_put_contents($filename, $jpg); echo file_get_contents ($filename); die;

but this is not working well(neigther I am getting filename, Not die stops script). Am I using wrong method to get the name ?

  • 写回答

1条回答 默认 最新

  • dongshi9407 2014-05-19 06:42
    关注

    You should know what is exactly raw POST data: $_POST can be said as and outcome after splitting the $HTTP_RAW_POST_DATA, PHP splits the raw post data and formats in the way we see it in the $_POST

    For example if $HTTP_RAW_POST_DATA looks something like this:

    key1=value1&key2=value2

    then $_POST would look like this:

    $_POST = array(
         "key1" => "value1",
         "key2" => "value2",);
    

    Most probably you include some other things (elements) from the post in your *.jpg data. Make sure you include only raw and valid *.jpg picture information, not other elements.

    Also keep in mind that $HTTP_RAW_POST_DATA is not available with form's type enctype="multipart/form-data".

    To get the Raw Post Data use:

    <?php $postdata = file_get_contents("php://input"); ?>

    php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives.

    More information here, here and here.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么