上传并保存具有原始名称的文件


Upload and save file with original name

您知道如何使用file_get_contents('php://input') 保存正在上传的文件吗

以下是我的

public function upload_image()
{
    $str = file_get_contents('php://input');
    $filename = md5(time()) . '.jpg'; // I don't want to use this line
    $path = public_path() . '/uploads/' . $filename; // I want to use original file name here
    file_put_contents($path, $str);
    echo $filename;
}

由于文件名不是由请求发送

你可以检查这些答案

如何在put请求中获取php中的文件名