閲覧数:1254
投稿日:2019-04-12
更新日:2019-04-12
ファイル出力するので
・適切なファイルパミッションを付与しないとエラー発生する
fopen(./20190412_var_export.txt): failed to open stream: Permission denied
具体的には
・FileZilaで「client-2」ディレクトリのパミッションを「777」へ変更
コード
$data = '山田裕子';
//1.var_export結果を、更新する度に追加出力していく
//var_export第2引数を TRUE に設定した場合、var_export() は変数表現を出力する代わりに返す。この書式はvar_dumpには適用できない
//書き込む文字列を指定する2番目のパラメータに、改行定数PHP_EOLを追加(改行あり)
$file = './'.date('Ymd').'var_export-1.txt';
file_put_contents($file,var_export($data,TRUE).PHP_EOL,FILE_APPEND);
//2.var_export結果を、更新する度に最新で上書出力する
$file = './'.date('Ymd').'var_export-2.txt';
file_put_contents($file,var_export($data,TRUE));
ob_start();
var_dump($data);
$obData =ob_get_contents();
ob_end_clean();
//1.var_dump結果を、更新する度に追加出力していく
$file = './'.date('Ymd').'var_dump-1.txt';
file_put_contents($file,$obData,FILE_APPEND);
//2.var_dump結果を、更新する度に最新で上書出力する
$file = './'.date('Ymd').'var_dump-2.txt';
file_put_contents($file,$obData);結果
'山田裕子' '山田裕子' '山田裕子' /var/www/xxxx/php-demo.w4c.work/demo/file-processing/file-output/customize/2/index.php:51: string(12) "山田裕子" /var/www/xxxx/php-demo.w4c.work/demo/file-processing/file-output/customize/2/index.php:51: string(12) "山田裕子" /var/www/xxxx/php-demo.w4c.work/demo/file-processing/file-output/customize/2/index.php:51: string(12) "山田裕子"