denoteone Posted September 12, 2010 Share Posted September 12, 2010 I have a function to writes data I want to make sure it was successful. my function: function save_ini_file($filename,$content) { $File = "ini_files/". $filename . ".ini"; echo $File; $Handle = fopen($File, 'w'); $info = $content; fwrite($Handle, $info); fclose($Handle); return true; } the if statement that calls the function. if(!save_ini_file($serial,$data)) { echo "did not write"; }else{ echo "did write"; } the file is being created but I am getting the "did not write" echoed Quote Link to comment https://forums.phpfreaks.com/topic/213200-check-to-make-sure-writing-to-file-was-successful/ Share on other sites More sharing options...
trq Posted September 12, 2010 Share Posted September 12, 2010 If you want to make sure your function executes successfully you need to at least check what it is doing. function save_ini_file($filename,$content) { $File = "ini_files/". $filename . ".ini"; if ($Handle = fopen($File, 'w')) { $info = $content; if (fwrite($Handle, $info)) { return true; } fclose($Handle); } return false; } Because there are several things that may go wrong within this function, you might also want to take look at having it throw exceptions. Quote Link to comment https://forums.phpfreaks.com/topic/213200-check-to-make-sure-writing-to-file-was-successful/#findComment-1110150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.