Upload many - store id
Upload many - store id
Hi,
is it possible to store the user id directly in the file ** table without using an extra **users_files (https://editor.datatables.net/examples/advanced/upload-many.html )
I mean like this:
->join(
Mjoin::inst( 'files' )
->fields(
Field::inst( 'id' )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/upload/__ID__.__EXTN__' )
->db( 'files', 'id', array(
'user_id' => 'users.id',
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH
) )
->validator( Validate::fileSize( 500000, 'Files must be smaller that 500K' ) )
->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
)
)
)
->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
I removed the ->link two times and added the user_id in the db area.
How can I submit the user id to the db area?
Is it possble to get a solution only with the users and files table (without an extra link with the users_files table)?
Thanks in advance
This question has an accepted answers - jump to answer
Answers
No - I'm afraid not. The
user
row (assuming we are talking about the examples here) might not have been created before the file was uploaded (which happens before the form is submitted).If however you have the user id as a session variable and you are meaning the user that is doing the upload, then yes, that is possible. Use something like:
Allan
ok obviously I have to create the users_files table :-)
I tried to set up a plain version and combine it with the parent / child exampe (https://datatables.net/blog/2016-03-25), but now I get the error "DataTables warning: table id=sites - Table part of the field "id" was not found. In Editor instances that use a join, all fields must have the database table set explicitly." but I have the field "id" in each table (see at db.txt).
Here is my site.php snippet:
Where is the mistake? Please can you help me again?
Kind regards
pib
I solved the issue, but I stoll don't get an entry in the users_files table.
This code works pretty well except the entry in the users_files table:
What should I add?
Thanks in advance?
pib
ok I always have to press the "update" button :-)
Is there any possibility to create the "users_files" entry directly without pressing the "update" button?
I'm afraid not. The form needs to be submitted for that write to happen. Consider for example the create case - the user id wouldn't exist until the row is interested into the database.
Regards,
Allan
ok thanks.
The file would be uploaded and the files entry get creates before the user presses the "Update" button, but who cares. I am fine with this solution :-)
Yes, that's the way it works at the moment. This has come up a few times recently, so I will look into providing an synchronous option for the upload in future.
Allan