summaryrefslogtreecommitdiff
path: root/includes/file.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/file.inc')
-rw-r--r--includes/file.inc31
1 files changed, 31 insertions, 0 deletions
diff --git a/includes/file.inc b/includes/file.inc
index 8994ea9d2..79f1b3f22 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -289,6 +289,37 @@ function file_save_upload($source, $dest = 0, $replace = 0) {
}
/**
+ * Save a string to the specified destination
+ *
+ * @param $data A string containing the contents of the file
+ * @param $dest A string containing the destination location
+ *
+ * @return A string containing the resulting filename or 0 on error
+ */
+function file_save_data($data, $dest, $replace = 0) {
+ if (!valid_input_data($data)) {
+ watchdog('error', t('Possible exploit abuse: invalid data.'));
+ drupal_set_message(t("file upload failed: invalid data."), 'error');
+ return 0;
+ }
+
+ $temp = variable_get('file_directory_temp', (PHP_OS == 'WINNT' ? 'c:\\windows\\temp' : '/tmp'));
+ $file = tempnam($temp, 'file');
+ if (!$fp = fopen($file, 'w')) {
+ drupal_set_message(t('unable to create file.'), 'error');
+ return 0;
+ }
+ fwrite($fp, $data);
+ fclose($fp);
+
+ if (!file_move($file, $dest)) {
+ return 0;
+ }
+
+ return $file;
+}
+
+/**
* Transfer file using http to client. Pipes a file through Drupal to the
* client.
*