【问题标题】:PHP file_put_contents Failed to open stream, invalid argumentPHP file_put_contents 无法打开流,参数无效
【发布时间】:2015-03-14 10:14:11
【问题描述】:

请帮忙!我已经尝试了一个多小时来解决这个问题 我要做的是通过 POST 获取表单值,然后将它们放入带时间戳的 txt 文件中 我得到的错误是:

警告:file_put_contents(D:\wamp\www\weboldal\hu\php\en\03-14-15-11:08:48.txt):无法打开流:D:\wamp\ 中的参数无效www\weboldal\hu\php\en\formprocessing2.php 第 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\n".$name."r\n".$email."r\n".$password;
    file_put_contents($fullfilename,$contents,LOCK_EX);

编辑:问题是 windows 不接受文件名中的冒号,感谢用户 @Hobo Sapiens 指出这一点

【问题讨论】:

  • 错误很直接,你确定文件路径是正确的吗?
  • 我猜 Windows 不喜欢文件名中的所有冒号。
  • @Neil Masters 我用 getchwd() 测试过,它返回“D:\wamp\www\weboldal\hu\php\en”
  • @Hobo Sapiens 非常感谢!这解决了我的问题
  • @RamRaider 用户 "Hobo Sapiens" 已经修复了它,问题是 Windows 不支持文件名中的 ":"

标签: php


【解决方案1】:

Windows 将拒绝带有时间戳的文件名,因为它是冒号。删除那些,你应该没事。

【讨论】:

  • LoLoL,我会在几个世纪以来一直在解决这个愚蠢的简单错误,不,几千年。希望您成为会员并为此获得积分。
猜你喜欢
  • 2015-09-28
  • 2015-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-22
  • 1970-01-01
  • 2013-04-25
  • 2019-11-09
相关资源
最近更新 更多