简体   繁体   中英

PHP, accept an uploaded file and then store its contents into a variable?

Much like this: http://www.w3schools.com/PHP/php_file_upload.asp

But I'd like to store the contents of the file into a variable. Is there a shortcut to this? (instead of saving it to a temp file, then opening the temp file and reading it into the variable)

No, uploaded files are always stored in a tmp file using the pattern shown in http://www.w3schools.com/PHP/php_file_upload.asp .

However, you could allow a POST and do something like:

$in = fopen("php://stdin", "rb");

curl -v -X POST -d @filetoupload.xml --header Content-Type:application/xml http://host.com

That's how PHP uploads the file, into a temporary file, which you can read into a variable. You can use the function move_uploaded_file if you want to move it somewhere without reading in the file contents and then writing them out, but there's not really any way to bypass the "upload to temp file" part of the process. You have to get it on the server somehow...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM