While adding ajax delete I came upon a dilemma.
Here's the function that confused me:
function _imagefield_file_delete($file, $fieldname) {
if (is_numeric($file['fid'])) {
db_query('DELETE FROM {files} WHERE fid = %d', $file['fid']);
}
else {
unset($_SESSION['imagefield'][$fieldname][$file['sessionid']]);
}
return file_delete($file['filepath']);
}
The file failed to be deleted from the session, since sessionid was not set. Never saw it anywhere.
This made accessing the file in session pretty hard, with the need to iterate through the whole $_SESSION[$fieldname].
So, I changed it to store the files in session by filename. An earlier patch (http://drupal.org/node/143686) makes this possible since the filename is unique. This allowed me to access the file in session easily.
I am attaching the patch detailing my changes. As you can see, nothing big.
Correct me if I was wrong...
This is one of the changes in http://drupal.org/node/144475 and other code depends on it.
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| storing_files_in_session.patch | 866 bytes | bojanz |
Comments
Comment #1
bojanz commentedForgot to change status
Comment #2
dopry commentedI think I snuck sessionid back into DRUPAL-5--2.. It got lost somehow, or I forgot about it one night :)....
Comment #3
(not verified) commented