I am trying to make an AJAX upload script from a static website accessible to Kirby, but I am failing to define the paths. Integrating the JavaScript is not a problem. But two PHP files are loaded in the JavaScript. How do I do this directly in JavaScript?
Nonetheless, the question is what your JS expects here. A url? A path? This is something not related to Kirby. I mean, the url to this script should be something like
And no, you cannot use PHP inside JavaScript, the alternative is usually using data attributes in your HTML or you could also use hidden input elements in your form with their values set to those script urls.
Stupid me… I made it unnecessarily complicated for myself. Of course, it works like this too.
Great, then the first problem is solved
Now it’s all about the upload folder.
This is currently located here: assets/vendors/uploader/upload
It would be better if the uploads ended up here: content/uploadstorage/
The path to the upload-foolder is stored in the file assets/vendors/uploader/ajax_upload.php
Btw: I tried your cookbook before. Side effect:I was also able to click on the upload button without selecting a file and then received an error message. So the cookbook did not work for my case. However, the solution with a drag-and-drop field is more convenient.
Because you asked about the error message, I uploaded the template and the controller from your cookbook again. What I noticed immediately: The drag-and-drop field from my new script is displayed because the CSS and JS file is still assigned in footer.php.
The upload works without errors and the template is assigned to the file. And if I upload an unsupported file type, the error message from the controller is displayed. So I have now turned your cookbook into a stylish drag-and-drop uploader.