From f5bf9c60c08fcc4cd61ad0756c04fcbed9819983 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 21 Dec 2005 16:56:11 +0000 Subject: [PATCH] Add error checking to file save. fixes #2109 git-svn-id: https://develop.svn.wordpress.org/trunk@3335 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/templates.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/wp-admin/templates.php b/wp-admin/templates.php index ee0e1d07f2..cc0d03ee49 100644 --- a/wp-admin/templates.php +++ b/wp-admin/templates.php @@ -41,12 +41,16 @@ case 'update': $newcontent = stripslashes($_POST['newcontent']); if (is_writeable($real_file)) { - $f = fopen($real_file, 'w+'); - fwrite($f, $newcontent); - fclose($f); - header("Location: templates.php?file=$file&a=te"); + $f = @ fopen($real_file, 'w+'); + if ( $f ) { + fwrite($f, $newcontent); + fclose($f); + header("Location: templates.php?file=$file&a=te"); + } else { + header("Location: templates.php?file=$file&a=err"); + } } else { - header("Location: templates.php?file=$file"); + header("Location: templates.php?file=$file&a=err"); } exit(); @@ -66,17 +70,25 @@ default: update_recently_edited($file); if (!is_file($real_file)) - $error = 1; + $error = true; if (!$error) { - $f = fopen($real_file, 'r'); - $content = fread($f, filesize($real_file)); - $content = htmlspecialchars($content); + $f = @ fopen($real_file, 'r'); + if ( $f ) { + $content = fread($f, filesize($real_file)); + $content = htmlspecialchars($content); + } else { + $error = true; + } } ?> + +

+

+