file_put_contents返回true,但不写入

时间:2020-05-05 08:10:46

标签: php json file file-put-contents

前言:我已经尝试了stackoverflow上指示的各种解决方案,但对我没有任何帮助。

我正在创建一种图形界面来查看和修改phpMailer配置参数等等。 我的问题是,当我从界面表单中编辑值时,不会保存它们。

我已验证,当我使用json_encode对json进行编码时,这些值就是我输入的值,但是当我去使用file_put_contents将其写入json文件时,这些值将不会保存。 >

我还附加了GUI屏幕,希望它会有用

技术规格:

Windows 10最新版本

Firefox最新版本

Chrome最新版本

xampp 3.2.4

php 7.4.2

    $Json_file = file_get_contents ('risorse/config.json');
$Json = html_entity_decode ($Json_file);
$Json = utf8_encode ($Json_file);
$Json = Json_decode($Json_file);

//Parametri Mail (Settaggi Mail)
$HostMail   = $Json -> configurazione [0] -> HostMail;  
$SMPT       = $Json -> configurazione [0] -> SMPT;      
$Porta      = $Json -> configurazione [0] -> Porta;     


$Username   = $Json -> login [0] -> Username;
$Password   = $Json -> login [0] -> Password;

$Template   = $Json -> template;

//Intestazione Mail
$Oggetto_OK             = $Json -> oggetto [0] -> Oggetto_OK;
$Oggetto_ALTRO          = $Json -> oggetto [0] -> Oggetto_ALTRO;
$Oggetto_Server_DOWN    = $Json -> oggetto [0] -> Oggetto_Server_DOWN;
$Oggetto_Server_STOP    = $Json -> oggetto [0] -> Oggetto_Server_STOP;

$Mittente           = $Json -> mittente_e_destinatario [0] -> Mittente;
$Destinatario       = $Json -> mittente_e_destinatario [0] -> Destinatario;

//Server
$Invia_se_ok    =  $Json -> invia_se_ok;
$Tempo          =  $Json -> tempo;
$Cartelle       =  $Json -> cartelle;   



/*******************************************************************
                    Parametri Mail (Settaggi Mail)
*******************************************************************/
if (PostVal ('HostMail')){
    $HostMail                               = PostVal ('HostMail');
    $Json -> configurazione [0] -> HostMail = PostVal ('HostMail');
}

if (PostVal ('SMPT')){
    $SMPT                                   = PostVal ('SMPT');
    $Json -> configurazione [0] -> SMPT     = PostVal ('SMPT');
}

if (PostVal ('Porta')){
    $Porta                                  = PostVal ('Porta');
    $Json -> configurazione [0] -> Porta    = PostVal ('Porta');
}

if (PostVal ('Username')){
    $Username                       = PostVal ('Username');
    $Json -> login [0] -> Username  = PostVal ('Username');
}

if (PostVal ('Password')){
    $Password                       = PostVal ('Password');
    $Json -> login [0] -> Password  = PostVal ('Password'); 
}

/*******************************************************************
                    Intestazione Mail
*******************************************************************/
if (PostVal ('Oggetto_OK')){
    $Oggetto_OK                                     = PostVal ('Oggetto_OK');
    $Json -> oggetto [0] -> Oggetto_OK              = PostVal ('Oggetto_OK');
}

if (PostVal ('Oggetto_ALTRO')){
    $Oggetto_ALTRO                                  = PostVal ('Oggetto_ALTRO');
    $Json -> oggetto [0] -> Oggetto_ALTRO           = PostVal ('Oggetto_ALTRO');        
}

if (PostVal ('Oggetto_Server_DOWN')){
    $Oggetto_Server_DOWN                            = PostVal ('Oggetto_Server_DOWN');
    $Json -> oggetto [0] -> Oggetto_Server_DOWN     = PostVal ('Oggetto_Server_DOWN');
}

if (PostVal ('Oggetto_Server_STOP')){
    $Oggetto_Server_STOP                            = PostVal ('Oggetto_Server_STOP');
    $Json -> oggetto [0] -> Oggetto_Server_STOP     = PostVal ('Oggetto_Server_STOP');
}

if (PostVal ('Mittente')){
    $Mittente                                           = PostVal ('Mittente');
    $Json -> mittente_e_destinatario [0] -> Mittente    = PostVal ('Mittente');
}

if (PostVal ('Destinatario')){
    $Destinatario                                           = PostVal ('Destinatario');
    $Json -> mittente_e_destinatario [0] -> Destinatario    = PostVal ('Destinatario');
}   

/*******************************************************************
                            Server
*******************************************************************/    
if (PostVal ('Invia_se_ok')){
    $Invia_se_ok            = 'checked';
    $Json -> invia_se_ok    = 'on';
}

if (!PostVal ('Invia_se_ok')){
    $Invia_se_ok = '';
    $Json -> invia_se_ok    = 'off';
}

if (PostVal ('Tempo')){
    $Tempo              = PostVal ('Tempo');
    $Json -> tempo      = PostVal ('Tempo');
}

if (PostVal ('Cartelle')){
    $Cartelle           = PostVal ('Cartelle');
    $Json -> cartelle   = PostVal ('Cartelle'); 
}



//RI codifico gli array in Json
$valori = Json_encode($Json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);   

stampa_debug('', $valori, 'var_dump');

//Salvo il Json nel file
if(file_put_contents('../config.json', $valori)){
    echo 'Modifiche Salvate';
}

else{
    echo 'Errore: le modifiche non sono state salvate';
}

Graphic Interface Screenshot

0 个答案:

没有答案
相关问题