方法:
function output($tip, $fileName = 'success')
{
$document = $_SERVER['DOCUMENT_ROOT'];
$newPath = '/uploads/';
$filePaht = $document. $newPath;
if (!is_dir($filePaht)) {
mkdir($filePaht, 0777, true);
}
$newFileName = $fileName. '.txt';
$handle=fopen($filePaht. '/'. $newFileName,"a");
fwrite($handle,"
-------------------------------------------
");
fwrite($handle,$tip);
fwrite($handle,"
-------------------------------------------
");
fclose($handle);
}
调用:
tip = '测试';
output($tip);
var_dump写入:
ob_start();
var_dump($model->errors, $v);
$result = ob_get_clean();
$this->output($result,'error');