Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
0c8a7c0d
Commit
0c8a7c0d
authored
Sep 2, 2007
by
Gábor Hojtsy
Browse files
Options
Downloads
Patches
Plain Diff
#168813
by chx: do not let form caching prevent file uploads
parent
85735002
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/upload/upload.module
+21
-22
21 additions, 22 deletions
modules/upload/upload.module
with
21 additions
and
22 deletions
modules/upload/upload.module
+
21
−
22
View file @
0c8a7c0d
...
@@ -165,17 +165,9 @@ function upload_file_download($file) {
...
@@ -165,17 +165,9 @@ function upload_file_download($file) {
* @param $node
* @param $node
* A node object to associate with uploaded files.
* A node object to associate with uploaded files.
*/
*/
function
_
upload_
prepare
(
&
$nod
e
)
{
function
upload_
node_form_submit
(
$form
,
&
$form_stat
e
)
{
global
$user
;
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.
// $_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
// 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
// it has been submitted. Since unchecked checkboxes have no return value and do not
...
@@ -199,9 +191,9 @@ function _upload_prepare(&$node) {
...
@@ -199,9 +191,9 @@ function _upload_prepare(&$node) {
}
}
// attach session files to node.
// attach session files to node.
if
(
count
(
$_SESSION
[
'upload_files'
]))
{
if
(
!
empty
(
$_SESSION
[
'upload_files'
]))
{
foreach
(
$_SESSION
[
'upload_files'
]
as
$fid
=>
$file
)
{
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) {
...
@@ -257,6 +249,7 @@ function upload_form_alter(&$form, $form_state, $form_id) {
$form
[
'#attributes'
][
'enctype'
]
=
'multipart/form-data'
;
$form
[
'#attributes'
][
'enctype'
]
=
'multipart/form-data'
;
}
}
}
}
$form
[
'#submit'
][]
=
'upload_node_form_submit'
;
}
}
}
}
...
@@ -274,10 +267,6 @@ function upload_nodeapi(&$node, $op, $teaser) {
...
@@ -274,10 +267,6 @@ function upload_nodeapi(&$node, $op, $teaser) {
}
}
break
;
break
;
case
'prepare'
:
_upload_prepare
(
$node
);
break
;
case
'view'
:
case
'view'
:
if
(
isset
(
$node
->
files
)
&&
user_access
(
'view uploaded files'
))
{
if
(
isset
(
$node
->
files
)
&&
user_access
(
'view uploaded files'
))
{
// Add the attachments list to node body with a heavy
// Add the attachments list to node body with a heavy
...
@@ -293,6 +282,16 @@ function upload_nodeapi(&$node, $op, $teaser) {
...
@@ -293,6 +282,16 @@ function upload_nodeapi(&$node, $op, $teaser) {
}
}
break
;
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
'insert'
:
case
'update'
:
case
'update'
:
if
(
user_access
(
'upload files'
))
{
if
(
user_access
(
'upload files'
))
{
...
@@ -390,7 +389,7 @@ function upload_save(&$node) {
...
@@ -390,7 +389,7 @@ function upload_save(&$node) {
// Remove file. Process removals first since no further processing
// Remove file. Process removals first since no further processing
// will be required.
// will be required.
if
(
$file
->
remove
)
{
if
(
!
empty
(
$file
->
remove
)
)
{
db_query
(
'DELETE FROM {upload} WHERE fid = %d AND vid = %d'
,
$fid
,
$node
->
vid
);
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,
// Remove it from the session in the case of new uploads,
// that you want to disassociate before node submission.
// that you want to disassociate before node submission.
...
@@ -400,7 +399,7 @@ function upload_save(&$node) {
...
@@ -400,7 +399,7 @@ function upload_save(&$node) {
}
}
// Create a new revision, or associate a new file needed.
// 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
);
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
);
file_set_status
(
$file
,
FILE_STATUS_PERMANENT
);
}
}
...
@@ -550,13 +549,13 @@ function upload_load($node) {
...
@@ -550,13 +549,13 @@ function upload_load($node) {
function
upload_js
()
{
function
upload_js
()
{
// We only do the upload.module part of the node validation process.
// We only do the upload.module part of the node validation process.
$node
=
(
object
)
$_POST
;
$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.
$files
=
isset
(
$_POST
[
'files'
])
?
$_POST
[
'files'
]
:
array
();
$node
->
files
=
upload_load
(
$node
);
// Handle new uploads, and merge tmp files into node-files.
_upload_prepare
(
$node
);
$form
=
_upload_form
(
$node
);
$form
=
_upload_form
(
$node
);
$form
+=
array
(
$form
+=
array
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment