]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11460 new function moodleform->get_file_content($elname) in case we need to get...
authorskodak <skodak>
Wed, 26 Sep 2007 16:53:26 +0000 (16:53 +0000)
committerskodak <skodak>
Wed, 26 Sep 2007 16:53:26 +0000 (16:53 +0000)
lib/formslib.php

index 0431b60003d6c5383b0f548c74bd6991a5e6b9a4..b0a5840a51cdada0e01ef19818d3081a7b1defeb 100644 (file)
@@ -419,6 +419,38 @@ class moodleform {
         return $this->_upload_manager->get_new_filename();
     }
 
+    /**
+     * Get content of uploaded file.
+     * @param $element name of file upload element
+     * @return mixed false in case of failure, string if ok
+     */
+    function get_file_content($elname) {
+        if (!$this->is_submitted() or !$this->is_validated()) {
+            return false;
+        }
+
+        if (!$this->_form->elementExists($elname)) {
+            return false;
+        }
+
+        if (empty($this->_upload_manager->files[$elname]['tmp_name'])) {
+            return false;
+
+        } else {
+            $data = "";
+            $file = @fopen($this->_upload_manager->files[$elname]['tmp_name'], "rb");
+            if ($file) {
+                while (!feof($file)) {
+                    $data .= fread($file, 1024); // TODO: do we really have to do this?
+                }
+                fclose($file);
+                return $data;
+            } else {
+                return false;
+            }
+        }
+    }
+
     /**
      * Print html form.
      */