How should the download.php file look like? I created a action in Sever Connect which filters the query with the hidden POST value to get the correct path and filename.
Hi.
The download.php file should be in the website folder to be accessible from form action. ../../../download.php makes me think, its not. So that’s the first thing you need to fix.
Next, the DokumentId hidden field’s name is hiddenField, so that is what you will need to access the ID.
If that is not the file name, bind file name in the hidden field.
Then, in download.php, you do not have to add app connect or server connects. Just hard code the path, and get the file name from $_POST['hiddenField'] in the readfile method.
Looking at the code, it seems are trying to fetch some document details to make the complete path.
If that is the case, you need to set the form as a Server Connect form and then send the document ID to the server action which would return the extra document details, from DB.
Create another form with action as download.php, method as post, and multiple hidden fields - 1 each for the extra details.
Then in the on-success event of main form server connect, set all the extra details in hidden fields of second form to value from main form server connect response. And, also submit the second form from on-success.
This all seems a bit overkill, but it will keep the path hidden. The file name and other details will still be visible… so if you can fetch it when you get the document ID, you will not need the second form and it will be a bit simpler.
thanks a lot for your time. I think I get the logic now. What I’m missing, is how to get the values for the second form. How do I get the posted values from my first form to insert them in the second form in the same page. Do I have to insert the Server Connect Action which I used in the form, a second time?
The main server connect form which you post documentID with, is the same place you will find the response values.
In the hidden field of second form, go to dynamic attribute > Set Value, then in the dynamic picker, find the main form, and you will see a data option which will contain the response.
A server connection form works exactly like a regular server connect, except that they need a form submit to be invoked.
SCForms also have the same events - executing, processing, start, done, error, success etc.
I succeeded with the correct values for my second form. What doesn’t work is that the second submit does not transfer the POST Values to the download.php file.
Clever with the 2 forms, but the problem is that App Connect updates the DOM async. The inputs in the second form probably didn’t update before the submit was called.
I will do some testing myself and see if I can find a better solution.
While Patrick gives a better solution, can you check if the download page is even getting called?
And if it is, what does print_r print?
If that part is working, any only the values are missing… try adding a delay to the success event of first form. dmx-on:success.debounce:300
This works even on some events which do not expose this option in the UI picker, but I haven’t tested with success event. Here 300 is milliseconds, probably enough time for App Connect to fill in the values.
NOTE: This looks like bit of a hack, but delay should work for you in this case as we are calling it only after we have data.
Don’t use it in inconsistent places, where flow of execution might take 2 seconds or 30.
That is great, didn’t think the debounce would work here.
For the download.php, make sure that only the php block is in there and there are no whitespaces before the <?php. Here a better script for the download.
Yes, it appears that you cannot just prefix the path with ../ to reference the folder above, not quite sure why that restriction should be there but it breaks the server action if you do
well we build that in as a security measurement long time ago in Server Connect.
Because people use often $_POST/$_GET input data into paths and that will make it so easy for hackers to access files and folders outside the wwwroot with just adding …/…/
You will that have your web server compromised in no time. So you should be really careful in allowing downloads outside website root. If not done well - people might gain full access to the whole system.
Yes, security is a concern in your case. As George already mentions a hacker could just post DateiPfad="/../../../etc" and Dateiname="passwd" to get the encrypted passwords file from your server. As extra security you could use realpath (https://www.php.net/manual/en/function.realpath.php) and check if the results starts with /usr/home/vewade. Or you do a database query in the download.php to get the path so that a user can’t manipulate it.