问题
I'm trying to upload a file automatically from a client-side script which opens a PHP page in my server sending a local path as a GET param. This is a simple python script. My problem is, I can not just fill in the value of an input type file and auto-post the form because for security reasons this doesn't work.
So, I thought of using Curl, but then I realized... I have no way of accessing a $_FILES['myfile']['tmp_name'] in my server because this is only posted with a multipart/form-data form, right?
Is there a way round this? Is there any other way to upload a file from a browser? It would be ideal to be able to do it with PHP since I'd like to use openID authentication to then save the uploaders email in MySQL database. Many thanks in advance.
回答1:
I think you haven't really understood why curl is not a viable solution. Your personal computer files are not exposed to the outside by default. Rather than that, if you want to share your hard disc you need to install and configure a lot of things:
- You need to configure your router so incoming connections are redirected to your PC
- You need to configure your firewall so incoming connections are let through
- You need to install a piece of software that can accept and serve file requests (a web server, a FTP server, a NFS server...)
- You need to instruct such software about what precise files you want to share (you don't want your complete hard disc drive open to the world)
- You probably want to restrict who has access to your files: username + password, certificate, IP address filter...
If you want to upload a file without user's intervention, the user needs to install a program in his computer that provides the feature: either one of those I've mentioned or a custom program. You can't do it with a barebones standard web browser.
You said something about a client-side Python script. Not sure about the meaning of client-side in Python context but Python is definitively able to open HTTP connections and send files. Follow that track.
来源:https://stackoverflow.com/questions/13858644/upload-a-file-with-php-curl-from-a-client-to-server