]> git.wh0rd.org - tt-rss.git/blobdiff - classes/opml.php
implement upload-related support for open_basedir
[tt-rss.git] / classes / opml.php
index 7a49f757c12c474dbe238004c444717a8a3446f8..2ecae42379ca5de4a7ad5a105fda8ecaf5d29f83 100644 (file)
@@ -461,11 +461,35 @@ class Opml extends Handler_Protected {
 
 #              if ($debug) $doc = DOMDocument::load("/tmp/test.opml");
 
-               if (is_file($_FILES['opml_file']['tmp_name'])) {
+               if ($_FILES['opml_file']['error'] != 0) {
+                       print_error(T_sprintf("Upload failed with error code %d",
+                               $_FILES['opml_file']['error']));
+                       return;
+               }
+
+               $tmp_file = false;
+
+               if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) {
+                       $tmp_file = tempnam(CACHE_DIR . '/upload', 'opml');
+
+                       $result = move_uploaded_file($_FILES['opml_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 = new DOMDocument();
-                       $doc->load($_FILES['opml_file']['tmp_name']);
+                       $doc->load($tmp_file);
+                       unlink($tmp_file);
                } else if (!$doc) {
-                       print_error(__('Error: please upload OPML file.'));
+                       print_error(__('Error: unable to find moved OPML file.'));
                        return;
                }