Executing local PHP file with Axios - javascript

I am trying to execute a local php file from the client with axios get. This is most likely not achievable from what I found out, except that this post has an answear that helped, unfortunately it is too vague for me to understand what he really ment by "environment hasn't got PHP installed", but it gave me hope. The OP had pretty much an identical issue like me.
The functionality of my php code is this - after taking the params from the get url it downloads a file in the same directory as the php file. I'm doing this, so I can have local access to the downloaded file in my client. Also I am doing it like that because I don't have access to the server side of the project.
If this is not possible after all, I found out that running my project throughout the xampp Apache server could work for me, but not sure if it is going to be ideal. I already confirmed that the php code works by running it trough Apache and using axios get to execute it, but I need the downloaded file in my project's local dir.

Well till this current moment there is no way to execute php file in the client without a server. But building and implementing my project into xampp Apache server did the trick better than I expected. It managed to help me simulate the path of the downloaded file so I can access it.
As #ceejayoz mentioned in his comment "they'll have to put the file in the right place, and you'll need to know the FQDN or IP address of their local server" so that the connection between the file from the server and the client has no issues.

Related

How to get data from web form into a file on the server [pm2]

So- I have some python scripts running permanently on my VPS and I want to be able to send them data to chew on via a simple web interface.
I do not mind how it gets the data. It seems to me that the simplest is probably to write the data to a file, and the python script automatically reads from this file every X seconds for changes. Then the solution need not involve python in any way.
From reading elsewhere, I believe the simplest solution is a simple php script. The problem here is that I'm running a pm2 server on the VPS. Pm2 does not support php I believe- and I can't install LAMP as this would presumably interfere with pm2.
I've looked into trying to do this with JS but that saves files client side and I need it server side.
I've also looked into cgi (I have zero experience with this) but pm2 doesn't seem to support this either?
Is there some fancy solution using node js?
What is the best way to tackle this problem!?

Where do I put front-end code in my backend project and how/when to run it?

The question is, say I have written a backend REST service using Python, and then some other guy wrote some frontend code in Angular JS. Is the typical workflow putting them into two separate folders and run them separately? So the process will look like below
python manage.py runserver
in Python colder and then probably
# in the angular2 folder
npm start
Or should I place all the JS code into some assets folder and when I start my server, all the JS code will run automatically with them? If so, how should I do it?
Another question related is, when is all the JS code sent to users’ browsers? If the app is a client-side rendering app, is the code sent to browser at the first time of server requesting? How does the server know it should package your JS code and ship it?
Q)The question is, say I have written a backend REST service using Python, and then some other guy wrote some frontend code in Angular JS. Is the typical workflow putting them into two separate folders and run them separately?
Both Angular and Python can be run differently as well as together.
You could choose to place the Angular files (which qualify for all practical purposes as public files) in the public (or related folder) depending on which framework you're using - Django, Flask, Web2py or so on.
You can also choose to run them independently as standalone apps.
Depends on your requirement. Honestly, there are so many ways to answer this question.
Q)Or should I place all the JS code into some assets folder and when I start my server, all the JS code will run automatically with them? If so, how should I do it?
If you place everything in your assets folder, then as soon as the home route or any other route is made a request for [from a browser] , the public folder passes on to the browser.
Although I'm not sure if it is the case with server side rendering.
If you're using Angular 1, I do not think it fits server side rendering although you could use some libraries out there.
Q)Another question related is, when is all the JS code sent to users’ browsers? If the app is a client-side rendering app, is the code sent to browser at the first time of server requesting? How does the server know it should package your JS code and ship it?
All the files in PUBLIC folder on the server are accessible by a browser.
All of your questions seem to essentially ask the same question.
There are many approaches to this problem.
If infrastructure management is difficult for you, than maybe it's easier to place them in the same server. You can create another directory and place your html that is served to browser with your JavaScript code.
In case you have a good pipeline (which I think it pays for it self) than having another server that serves your application is better. You can do more things without affecting your service, like caching etc. And your server that runs your service wont be busy serving assets as well.
I have a case where we run a node server, which serves the html and javascript to our users, because that way we can do server side rendering.enter link description here
The flow of code execution will be this : Once the browser of your user hits the server that is serving html and assets, it will download it locally and it will start with JavaScript execution (Parsing, Compiling and Executing). Your JavaScript app might do some API calls upon initialization or it might not, but your service will be executed only if frontend makes a request.
As for CORS it is irrelevant how you serve them, because you can keep them always in the same domain.

Can I create a directory in client PC?

I have multiple questions
Can we create a directory in client machine ?
Can we check the running browser's default download path?
My requirement is that the user will download a BLOB data from my DB that time I want to create a folder in client machine and use that folder to save the blob data.
Can this be done using javascript,jquery,ajax,php,angularjs ?
You can't create a folder in client PC using JS.(don't even bother looking with HTML and CSS)
The best way you could accomplish something as you describe is to give a .zip to your client, so while extracting it, it creates his own container (the folder). But you must be sure that the people who intend using your web application knows how a .zip works.
Using PHP you can't do anything in the client PC. PHP is a server side programming language. So, it is running only in the server. When you make any request to the server then only PHP performs. In the browser end or client side only HTML, CSS and JS works.

Getting a Python server to execute a script

I'm pretty new to web development, so bear with me if these questions seem pretty fundamental.
My use-case is as follows: I am hosting a server using ngrok which allows me to allow clients to securely tunnel to a server I host locally, using a public http(s) URL that ngrok generates.
Currently the server I am running locally is the simplest possible python web server (I literally just invoke 'python -m SimpleHTTPServer 8080').
Let's say I have a file "simplescript" located in the local directory where I instantiate the Python server. I would like to put in php code in "simplescript" so that when somebody fetches the file by using the browser to access "https://ngrokURL.ngrok.io/simplescript", then my server will execute the php code in the script directly and return the return value (if one is generated) to the client requesting my file.
Right now, when I try to do this, the client accessing my file only receives the actual text content of the script, and so it seems that the script is not being executed at all.
Question:
Is my use-case something that can be achieved using the Python simple HTTPserver, or do I need other tools?
How can I make my scripts executable for my server (if that is something I have to do)?
Thanks for the help!

How to protect admin javascript file?

I have a javascript file for admin page only in my site. How to do that, the file was available only for admins. Checking roles performed by cookies. Maybe some sort of a check on the server? Server apache.
ps: sorry for my bad english.
Even if you check cookies from Javascript code [it is possible to check] but the JS will still get downloaded on client computer. I think you want such that no other than admin can download the file. If that is the case, then better use .htaccess or web.config file to resrtict folder which contain admin specific files for proper authentication.
in a tricky solution you can use URL Rewriting as well to prevent file download unless your PHP or server side code verify the user.

Categories

Resources