php FILE POST upload without save

前端 未结 6 2394
深忆病人
深忆病人 2021-02-18 23:49

I am using a plain text file in a PhP script. Is there any way to process the file in the PhP script without saving it locally? Everywhere I see simply uploading a file and sav

6条回答
  •  失恋的感觉
    2021-02-18 23:55

    If its text file (assuming size is not that huge) usually you could read it by

    $contents= file_get_contents($_FILES['file']['tmp_name']);
    

    If you are not sure which type of upload it was, check the request method

    if(strtolower($_SERVER['REQUEST_METHOD'])=='post')
        $contents= file_get_contents($_FILES['file']['tmp_name']);
    elseif(strtolower($_SERVER['REQUEST_METHOD'])=='put')
        $contents= file_get_contents("php://input");
    else
        $contents="";
    

提交回复
热议问题