1

私はこの問題の新入生なので、phpをテストしています。私は自分のphpコードを無料のサーバーに置き、自分のindex.phpを実行させ、いくつかのphp変数(register_globals、magic_quotes_gpcなどをデフォルトのままにしました)を管理しますが、どうやら1つのファイルで処理できるファイルは1つだけです。 phpコード、例:

<?php

//--------Updating Data-------------
$cdc = intval($_POST['cantidadDeCapitulos']);
$toWrite = array('ctot' => $cdc);
for($i=1;$i<$cdc+1;$i += 1){
   $toWrite["cap".$i] = $_POST['numdeCap'.$i];
}//---------------------------------

$datos = file_get_contents("myfile.json.");

$toWrite = json_encode( $toWrite );

//Open a file in write mode

$fp = fopen("myfile2.json", "w");

if(fwrite($fp, "$toWrite")) { 
  echo "&verify=success&"; 
} else { 
  echo "&verify=fail&"; 
}
fclose($fp);
?>

この行をコメントアウトすると、$datos = file_get_contents("myfile.json.");大丈夫です!myfile2.jsonに何かが書き込まれますが、コメント化されていない場合、データは更新されません。両方のファイルには権限666があり、同じディレクトリ、つまり/rootにあります。

4

2 に答える 2

1
$datos = file_get_contents("myfile.json.");

タイプミスが発生したようです。ファイルから最後のドットを削除します。つまり、行を次のように変更します。

$datos = file_get_contents("myfile.json");
于 2012-10-26T18:56:30.097 に答える
0

これを試して:

<?php
$file = 'myfile.json';
// Open the file to get existing content

$current = file_get_contents($file);

// Write the contents back to the file
file_put_contents($file, $current);
?>
于 2012-10-26T19:34:41.170 に答える