在编写和打开文件时为什么php会崩溃?

时间:2017-03-24 22:43:40

标签: php

php在打开和写入文件时如何出错。

function makeImage() {
    $encoded_string = $_POST['encoded_string'];
    $decoded_string = base64_decode($encoded_string);
    $path = "C:\Inetpub\vhosts\apbclt.com\httpdocs\php\logo".$_POST['company_name'];
    $file = fopen($path, 'wb');
    $is_written = fwrite($file, $decoded_string);
    fclose($file);
    if($is_written > 0) {
        global $mysqli;
        $stmt = $mysqli->prepare("INSERT INTO Companies (logo) VALUES (?)");
        $stmt->bind_param("s", $path);
        $stmt->execute();
        $stmt->store_result();
        if($stmt->affected_rows > 0) {
            $stmt->close();
            return true;
        }else{
            $stmt->close();
            return false;
        }
    }
}

这是错误

PHP Warning:  fopen(C:\Inetpubhosts\apbclt.com\httpdocs\php\logo): failed to open stream: Invalid argument in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 54
PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 55
PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 56

我搜索过但没有回答我的情况。

更新::

当我将\ v更改为\ v时,就像第一个回答一样,我收到了以下错误。

PHP Warning:  fopen(C:\Inetpub\vhosts\apbclt.com\httpdocs\php\logo): failed to open stream: Permission denied in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 54
PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 55
PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 56

1 个答案:

答案 0 :(得分:0)

确定我解决了这个问题,而不是使用完整的文件路径我刚刚使用路径返回文件夹..\logo