消息:fopen()期望参数1为有效路径,给定数组 [英] Message: fopen() expects parameter 1 to be a valid path, array given

查看:106
本文介绍了消息:fopen()期望参数1为有效路径,给定数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用库以.ini格式写文件。

I am using an Library to write files in .ini format.

现在这是我的写函数:

function write($file = NULL, $data = array(), $sections = TRUE) {
    $this->data = (!empty($data)) ? $data : $this->data;
    $this->file = ($file) ? $file : $this->file;
    $this->sections = $sections;
    $content = NULL;

    if ($this->sections) {
        foreach ($this->data as $section => $data) {
            $content .= '[' . $section . ']' . PHP_EOL;
            foreach ($data as $key => $val) {
                if (is_array($val)) {
                    foreach ($val as $v) {
                        $content .= $key . '[] = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
                    }
                } elseif (empty($val)) {
                    $content .= $key . ' = ' . PHP_EOL;
                } else {
                    $content .= $key . ' = ' . (is_numeric($val) ? $val : '"' . $val . '"') . PHP_EOL;
                }
            }
            $content .= PHP_EOL;
        }
    } else {
        foreach ($this->data as $key => $val) {
            if (is_array($val)) {
                foreach ($val as $v) {
                    $content .= $key . '[] = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
                }
            } elseif (empty($val)) {
                $content .= $key . ' = ' . PHP_EOL;
            } else {
                $content .= $key . ' = ' . (is_numeric($val) ? $val : '"' . $val . '"') . PHP_EOL;
            }
        }
    }

    return (($handle = fopen($this->file, 'w')) && fwrite($handle, trim($content)) && fclose($handle)) ? TRUE : FALSE;
}

然后我写我的内容,我给文件是这样的:

And i write my content i give the file like this:

                $file = $path.$filename;

                $ini = new INI($file);



                    // Save settings to file
                $ini->write($insert);

ON VAR_DUMP($ ini);我得到了:

ON VAR_DUMP($ini); i get :

object(INI)[76]
  public 'file' => string 'C:/wamp/www/bizrtc/uploads/test1.ini' (length=36)
  public 'data' => 
    array (size=3)
      'INIDetails' => 
        array (size=11)
          'SipUserName' => string '' (length=0)
          'Password' => string '' (length=0)
          'Domain' => string '' (length=0)
          'Proxy' => string '' (length=0)
          'Port' => string '' (length=0)
          'SipAuthName' => string '' (length=0)
          'DisplayName' => string '' (length=0)
          'ServerMode' => string '' (length=0)
          'UCServer' => string '' (length=0)
          'UCUserName' => string '' (length=0)
          'UCPassword' => string '' (length=0)
      'DialPlan' => 
        array (size=3)
          'DP_Exception' => string '' (length=0)
          'DP_Rule1' => string '' (length=0)
          'DP_Rule2' => string '' (length=0)
      'Advanced' => 
        array (size=14)
          'OperationMode' => string '' (length=0)
          'MutePkey' => string '' (length=0)
          'Codec' => string '' (length=0)
          'PTime' => string '' (length=0)
          'AudioMode' => string '' (length=0)
          'SoftwareAEC' => string '' (length=0)
          'EchoTailLength' => string '' (length=0)
          'PlaybackBuffer' => string '' (length=0)
          'CaptureBuffer' => string '' (length=0)
          'JBPrefetchDelay' => string '' (length=0)
          'JBMaxDelay' => string '' (length=0)
          'SipToS' => string '' (length=0)
          'RTPToS' => string '' (length=0)
          'LogLevel' => string '' (length=0)
  public 'sections' => boolean true

我错了吗?我应该怎么做才能使它正常工作?

where i am wrong? what should i do to let this work?

推荐答案

如果没有整个类和错误的行号,可能很难猜测。该方法似乎可以,至少可以使用fopen。在我看来,您的财产似乎已被其他地方覆盖。尝试将其设为私有,然后看看会发生什么,也许这可以帮助您发现问题。

Without entire class and line number of an error it can be difficult to guess. The method seems to be ok, at least the part with fopen. To me it seems like your property has been overriden somewhere else. Try to make it private and see what happens, maybe this will help you to spot the problem.

这篇关于消息:fopen()期望参数1为有效路径,给定数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆