How to get filename in php in put request

后端 未结 2 1761
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 18:58

I know we can read put request in file using

file_get_contents(\"php://input\");

But how do i get the filename in the put request?

2条回答
  •  借酒劲吻你
    2020-12-19 19:22

    If you're using PUT like in PUT Method Support page, you can get the filename they PUT to as $_SERVER['REQUEST_URI']

    For example, if I have the receiving PHP script

    
    

    When I issue the CURL:

    curl -X PUT -T "localfile.txt" http://example.com/interesting/target/name.txt
    

    I get the output (in my error log)

    Received PUT,  filename: interesting/target/name.txt, 4931 bytes
    

    If you're asking how I could find out the name the file had back on the source file system (localfile.txt) I don't think that gets passed along.

提交回复
热议问题