Reputation: 1037
I am using Jquery-File-Upload plugin. When plugin is loaded I add already preloaded files with this code:
var files = [
{
"name": ""+uploadFileName+"",
// "size":775702,
"type": "audio/ac3",
"url": ""+uploadFile+"",
"deleteUrl": ""+uploadFile+"",
"deleteType": "DELETE"
}
];
var $form = $('#fileupload');
// Init fileuploader if not initialized
// $form.fileupload();
$form.fileupload('option', 'done').call($form, $.Event('done'), {result: {files: files}});
Everything works fine - plugin add file to the fileslist but in this case (with manually preload) DELETE button doesn't work and doesn't delete the file.
In console I see the error: DELETE (*url_link*) 405 (Method Not Allowed)"
.
Anyone knows how to fix this problem and what kind of problem is it?
P.S. I don't create manually these delete buttons both ways. But with uploading new file I can't delete file and I can't when trying to delete the old one.
Any help will be helpful!
Upvotes: 1
Views: 1630
Reputation: 11
I had the same problem with this plugin, it took almost a month to find the solution and it's very simple.
Change the UploadHandler.php
file lines:
'user_dirs' => false
'delete_type' => 'DELETE'
to the following :
'user_dirs' => true
'delete_type' => 'POST'
Upvotes: 1
Reputation: 1037
I found the answer.
In API documentation there is no any information about deleteUrl
parameter so I thought that url
and deleteUrl
are same links.
To fix 405 error
and make DELETE button workable you need to configure it right (in case of manual preloading). PHP code is below but you can understand the whole process and implement it to another languages:
$settings_location_folder = "materials/";
$actual_location_folder = "materials/files"; //plugin requires such structure
$url_link_from_db = "filename.mp3";
$url = $actual_location_folder."".$url_link_from_db; //url = "materials/files/filename.mp3";
$deleteUrl = $settings_location_folder."index.php?file=".$url_link_from_db; //deleteUrl = "materials/index.php?file=filename.mp3";
So if you have 405 error
with click on DELETE button – check deleteUrl
parameter and add index.php?file=
before link on the file inside the folder where the file currently located.
Hope it save your time in the future if you will face with the same problem.
Upvotes: 1