File upload problem
File upload problem
Hello,
I have a form for teacher activities which contain upload file. The form work fine , but sometimes the file uploaded and display in the form and after click sumit the file and its info in the db removed. As I said this happen sometimes. I used custom upload file , but the problem does not solve.
My code and db is as this example
https://editor.datatables.net/examples/advanced/upload.html
Regards
Replies
Odd. When it does happen, are you seeing console errors in the browser, or any server-side errors, either in the database or web server logs?
Colin
Hello Colin,
the data stored in the activities table, so there is no error. Also, the image_id field in the activities table take a value from images table and after submission the row remove from images table.
Do you have a
dbClean
function defined on the server-side? Also, are multiple people accessing and modifying data at the same time?Allan
Hello Allan,
Yes, I have dbClean in server-side and more than people accessing on the same time.
I suspect that might be what is happening in that case. If dbClean runs it will find orphaned records. So if you happen to upload a file, then someone else edits a row before you submit your form, it will find your file as an orphan and delete it.
Do you have a "created" field in the database for the file? If so, you could add a check into it to make sure that it only deletes orphaned files which are older than a day which would resolve that issue.
Allan
Hello Allan,
I have "Uploaded_Date" field in the activities table. If you mean in the images table, I don't have. I will add it and let you know.
Thanks Allan
Hello Allan,
I added created field as "date" to the images table and add check if the date equal a day or older then delete file as below, but the problem is in the last line "return true" which will delete all orphaned files info from database.
Here is my code
Thanks
Sorry this is the correct one.
I added created field as "date" to the images table and add check if the date equal a day or older then delete file as below, but the problem is in the last line "return true" which will delete all orphaned files info from database.
Here is my code
Thanks
Hello Allan,
I solved as follow. Is this correct or not?
Regards
Hi,
Yes, that looks like a good solution to me. I must admit I'd thought dbClean was called once per file, but that obviously isn't the case, apologies. I'll have a look at adding something to make this kind of thing easier in future!
Until then, your solution looks spot on.
Regards,
Allan
Thanks Allan,
Also, In my system the people upload files alot, so for my case which is better the default upload as in the upload file example or custom upload?
Thanks again
Either could work fine. If the default upload does what you need, then I'd go with that. Only if you need to customise it would you need the custom upload.
Allan
Thanks alot Allan