duan6832168 2015-03-14 10:14
浏览 97
已采纳

PHP file_put_contents无法打开流,无效参数

Please help! I have tried figuring this out for over an hour What i am trying to do is to get form values via POST, and then put these into a timestamped txt file The error i get is:

Warning: file_put_contents(D:\wamp\www\weboldal\hu\php\en\03-14-15-11:08:48.txt): failed to open stream: Invalid argument in D:\wamp\www\weboldal\hu\php\en\formprocessing2.php on line 18

if ($_POST["type"] == "Type1") {
    print "Type1";
    $filename = date("m-d-y-h:i:s");
    $fullfilename = "D:\\wamp\\www\\weboldal\\hu\\php\\en\\".$filename.".txt";
    print $fullfilename;
    while (file_exists($fullfilename)) {
        print "Please wait a few seconds, server is busy";
        sleep(1);
    }
    $type = $_POST["type"];
    $name = $_POST["name"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $contents = $type."r
".$name."r
".$email."r
".$password;
    file_put_contents($fullfilename,$contents,LOCK_EX);

EDIT: The problem was that windows would not accept colons in the filename, thanks to user @Hobo Sapiens for pointing that out

  • 写回答

1条回答 默认 最新

  • douyiqi9640 2015-03-14 10:27
    关注

    Windows will reject the filename with the timestamp as it is because of the colons. Remove those and you should be fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题