使用原始名称上传并保存文件
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;
}
您需要将文件名与表单参数一起传递,因为文件名不是
由请求发送
您可以查看这些答案
How to get filename in php in put request
您知道如何使用 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;
}
您需要将文件名与表单参数一起传递,因为文件名不是 由请求发送
您可以查看这些答案
How to get filename in php in put request