Jump to content

[SOLVED] passing an uploaded file to a Python script


friedemann_bach

Recommended Posts

I need to solve a problem concerning Python and PHP.

 

An uploaded document has to be processed by a Python script. Up to now, this was done by calling the Python script directly from an upload form (<form ... action="../cgi-bin/upload.py">). This worked well.

 

Now, the page has to be transfered to a new webserver that does not allow posting directly to the Python script, as the CGI-BIN folder should not be available through a php or html form, but only on server side.

 

I tried to post the document to a PHP script that calls the Python script, e. g. by "passthru( ... /upload.py)". This works, but the uploaded document is no longer available. It seems that the post data is not passed to the Python script. Can anybody help?

 

The document should still be available. Here are the steps I would use, hopefully they will help you find your problem.

 

-Form posts to PHP script

-PHP script uses move_uploaded_file() to put the upload in a temporary location. If you want a unique filename, I would use getmypid()

-If the path to the script is a relative path, use realpath() to get the absolute path the python script

-Use a system command (passthru/system/exec) to call the python script, passing the absolute path to the temp file as an argument

-Process the file with the python script

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.