From 3306daecf4450555961490c11e70e7cf7fe7b86e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 11 Apr 2013 19:12:00 +0400 Subject: implement upload-related support for open_basedir --- plugins/googlereaderimport/init.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'plugins/googlereaderimport') diff --git a/plugins/googlereaderimport/init.php b/plugins/googlereaderimport/init.php index ac7a872f2..f7d876b90 100644 --- a/plugins/googlereaderimport/init.php +++ b/plugins/googlereaderimport/init.php @@ -66,8 +66,32 @@ class GoogleReaderImport extends Plugin { $owner_uid = $_SESSION["uid"]; - if (is_file($_FILES['starred_file']['tmp_name'])) { - $doc = json_decode(file_get_contents($_FILES['starred_file']['tmp_name']), true); + if ($_FILES['starred_file']['error'] != 0) { + print_error(T_sprintf("Upload failed with error code %d", + $_FILES['starred_file']['error'])); + return; + } + + $tmp_file = false; + + if (is_uploaded_file($_FILES['starred_file']['tmp_name'])) { + $tmp_file = tempnam(CACHE_DIR . '/upload', 'starred'); + + $result = move_uploaded_file($_FILES['starred_file']['tmp_name'], + $tmp_file); + + if (!$result) { + print_error(__("Unable to move uploaded file.")); + return; + } + } else { + print_error(__('Error: please upload OPML file.')); + return; + } + + if (is_file($tmp_file)) { + $doc = json_decode(file_get_contents($tmp_file), true); + unlink($tmp_file); } else { print_error(__('No file uploaded.')); return; -- cgit v1.2.3