简体   繁体   English

PHP:File_put_content不会创建文件

[英]PHP: File_put_content doesn't create the file

this is really strange, this php code worked well for a long time 这真的很奇怪,这个php代码长期以来都运行良好

<?php
header('Content-type: application/json');

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
  $data = file_get_contents("php://input");
  $arr = explode(' ',trim($data));
  $file =  $arr[0];
  $my_file = "bet_shared/".$file;
  $sharing_bet = strstr($data," ");
  file_put_contents($my_file, $sharing_bet);
}
else
{
    var_export($_SERVER['REQUEST_METHOD']);
}
?>

Now the method file_put_contents($my_file, $sharing_bet) doesn't create the file in bet_shared directory. 现在,方法file_put_contents($ my_file,$ sharing_bet)不在bet_shared目录中创建文件。 All the permission in folder and directory are setted to 777 so the other question are unusefull for me! 文件夹和目录中的所有权限都设置为777,所以另一个问题对我来说毫无用处! am I missing somethink? 我想念什么吗?

Finally I sorted Out: the script is called from an android application and this was my java code to create a connection and POST some strings 最后我整理了一下:从一个android应用程序调用了该脚本,这是我的Java代码来创建连接并发布一些字符串

 URL url = new URL(URL_STRING);
                HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
                conn.setConnectTimeout(CONNECTION_TIMEOUT);
                conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
                //conn.setDoOutput(true);
                conn.setDoInput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");
                conn.connect();

                OutputStream os = conn.getOutputStream();
                os.write(jsonBet.getBytes("UTF-8"));
                os.close();

I sorted adding this code below: 我对以下代码进行了排序:

                if (200 <= conn.getResponseCode() && conn.getResponseCode() <= 299) {
                    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    Log.i("response = " , br.readLine());
                } else {
                    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
                    Log.i("response two = " , br.readLine());

                }

Seems like the connection goes down without setting a response code 好像连接失败而没有设置响应代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM