summaryrefslogtreecommitdiff
path: root/modules/upload
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-09-02 14:26:26 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-09-02 14:26:26 +0000
commit0c8a7c0de7324466ccc435c1afa4babd30d55bd9 (patch)
tree5cc97c80497fb842bef6582ba68fb840d420f794 /modules/upload
parent85735002c33a27518d23bc6a24917c33ea98b840 (diff)
downloadbrdo-0c8a7c0de7324466ccc435c1afa4babd30d55bd9.tar.gz
brdo-0c8a7c0de7324466ccc435c1afa4babd30d55bd9.tar.bz2
#168813 by chx: do not let form caching prevent file uploads
Diffstat (limited to 'modules/upload')
-rw-r--r--modules/upload/upload.module43
1 files changed, 21 insertions, 22 deletions
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index 83784c2bd..b10d99631 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -165,17 +165,9 @@ function upload_file_download($file) {
* @param $node
* A node object to associate with uploaded files.
*/
-function _upload_prepare(&$node) {
+function upload_node_form_submit($form, &$form_state) {
global $user;
- // Initialize _SESSION['upload_files'] if no post occurred.
- // This clears the variable from old forms and makes sure it
- // is an array to prevent notices and errors in other parts
- // of upload.module.
- if (!$_POST) {
- $_SESSION['upload_files'] = array();
- }
-
// $_SESSION['upload_current_file'] tracks the fid of the file submitted this page request.
// form_builder sets the value of file->list to 0 for checkboxes added to a form after
// it has been submitted. Since unchecked checkboxes have no return value and do not
@@ -199,9 +191,9 @@ function _upload_prepare(&$node) {
}
// attach session files to node.
- if (count($_SESSION['upload_files'])) {
+ if (!empty($_SESSION['upload_files'])) {
foreach($_SESSION['upload_files'] as $fid => $file) {
- $node->files[$fid] = $file;
+ $form_state['values']['files'][$fid] = $file;
}
}
}
@@ -257,6 +249,7 @@ function upload_form_alter(&$form, $form_state, $form_id) {
$form['#attributes']['enctype'] = 'multipart/form-data';
}
}
+ $form['#submit'][] = 'upload_node_form_submit';
}
}
@@ -274,10 +267,6 @@ function upload_nodeapi(&$node, $op, $teaser) {
}
break;
- case 'prepare':
- _upload_prepare($node);
- break;
-
case 'view':
if (isset($node->files) && user_access('view uploaded files')) {
// Add the attachments list to node body with a heavy
@@ -293,6 +282,16 @@ function upload_nodeapi(&$node, $op, $teaser) {
}
break;
+ case 'prepare':
+ // Initialize $_SESSION['upload_files'] if no post occurred.
+ // This clears the variable from old forms and makes sure it
+ // is an array to prevent notices and errors in other parts
+ // of upload.module.
+ if (!$_POST) {
+ $_SESSION['upload_files'] = array();
+ }
+ break;
+
case 'insert':
case 'update':
if (user_access('upload files')) {
@@ -390,7 +389,7 @@ function upload_save(&$node) {
// Remove file. Process removals first since no further processing
// will be required.
- if ($file->remove) {
+ if (!empty($file->remove)) {
db_query('DELETE FROM {upload} WHERE fid = %d AND vid = %d', $fid, $node->vid);
// Remove it from the session in the case of new uploads,
// that you want to disassociate before node submission.
@@ -400,7 +399,7 @@ function upload_save(&$node) {
}
// Create a new revision, or associate a new file needed.
- if (!empty($node->old_vid) || array_key_exists($fid, $_SESSION['upload_files'])) {
+ if (!empty($node->old_vid) || isset($_SESSION['upload_files'][$fid])) {
db_query("INSERT INTO {upload} (fid, nid, vid, list, description) VALUES (%d, %d, %d, %d, '%s')", $file->fid, $node->nid, $node->vid, $file->list, $file->description);
file_set_status($file, FILE_STATUS_PERMANENT);
}
@@ -550,13 +549,13 @@ function upload_load($node) {
function upload_js() {
// We only do the upload.module part of the node validation process.
$node = (object)$_POST;
- $files = isset($_POST['files']) ? $_POST['files'] : array();
+ $form_state = array();
+ // Handle new uploads, and merge tmp files into node-files.
+ upload_node_form_submit(array(), $form_state);
+ $node->files = array_merge(isset($form_state['values']['files']) ? $form_state['values']['files'] : array(), upload_load($node));
- // Load existing node files.
- $node->files = upload_load($node);
+ $files = isset($_POST['files']) ? $_POST['files'] : array();
- // Handle new uploads, and merge tmp files into node-files.
- _upload_prepare($node);
$form = _upload_form($node);
$form += array(