我在文件上传方面遇到问题。我想按名称或本地路径文件上传文件。 我尝试使用
$app->post('/books/cover/{id}', function (Request $request, Response $response, array $args) {
$path = "d:\\1.jpg";
$file = basename($path);
$uploadedFile = $file;
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
$filename = sprintf('%s.%0.8s', $args["id"], $extension);
$directory = $this->get('settings')['upload_directory'];
$uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
return $response->withJson(["status" => "failed", "data" => "0"], 200);
}
});