I am making a post request with some javascript to a python script in my /var/www/cgi-bin
on my web server, and then in this python script I want to save the image file to my html folder, so it can later be retrieved.
Located at /var/www/html
, but right now the only way I know how to do this is to set the python script to chmod 777
which I do not want to do.
So how else can I save a file that I grab from my webpage using javascript and then send to server with javascript via POST?
Currently when I do this I get an error saying the python does not have permission to save, as its chmod is 755
.
I here is python code, I know it works as the error just says I dont have permission to write the file
fh = open("/var/www/html/logo.png", "wb")
fh.write(photo.decode('base64'))
fh.close()
If id is 1, it will write my website logo to the client, else it will write my 404 icon image to the client. As with HTTP get, downloading of a file from the web server via HTTP post in C# consists of three main steps: Construct the HTTP post request to send to the web server. Send the HTTP request and get the HTTP response from the web server.
You can send data to the server in the body of the POST message. The type and size of data are not limited. But you must specify the data type in the Content-Type header and the data size in the Content-Length header fields. The HTTP POST requests can also send data to the server using the URL parameters.
In the example below, the "method=POST" form attribute tells the browser to submit the webform using the HTTP POST method, and the "action=/login" attribute specifies the destination URL. In JavaScript, you can send HTTP requests using the XMLHttpRequest object or the new Fetch web API.
Send the HTTP request and get the HTTP response from the web server. Stream httpResponseStream = httpResponse.GetResponseStream (); Sometimes, there is a need for the client to supply some information to the web server in order to download a file. This can be a case when we want to control how files are downloaded.
If you don't want to change the permission of that directory to 777
, you can change the owner of the directory to your HTTP server user, then the user of your web app will be able to write file into that directory because they have rwx - 7
permission of the directory.
To do that, via (since you're using Apache as your web server, remember login as `root):
chown -R apache:apache /var/www/cgi-bin/
Remember that then only user apache
and root
has rwx
to that directory, and others has rx
.
And this command means:
chown - change the owner of the directory
-R - operate on files and directories recursively
apache:apache - apache user, apache group
/var/www/cgi-bin/ - the directory
Try man chown
command to check the manual page of chown
and learn more, here's a online version.
If you need change it back, I think the default user of that directory is root
. So login as root
, and run command:
chown -R root:root /var/www/cgi-bin/
We were solved the problem in chat room.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With