按目录文件超薄上传文件

时间:2018-12-17 06:10:09

标签: slim

我在文件上传方面遇到问题。我想按名称或本地路径文件上传文件。 我尝试使用

$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);
}
});

0 个答案:

没有答案
相关问题