dongxianrang9269 2016-01-16 04:15
浏览 53
已采纳

超薄框架3上传

I have problem upload files through slim framework 3 Slim\Http\UploadedFile.

My code:

$app->post('/upload', function ($req, $res, $args) {
    $setting = $this->settings;
    $uploadPath = $setting['upload']['path'];
    $file = $req->getUploadedFiles()['img'];
    $file->moveTo($uploadPath);
    return $res;
});

Result:

Slim Application Error
The application could not run because of the following error:

Details

Type: RuntimeException
Message: Error moving uploaded file hss.png to /home/xxx/web/slim3/app/../log
File: /home/xxx/web/slim3/vendor/slim/slim/Slim/Http/UploadedFile.php
Line: 237
  • 写回答

3条回答 默认 最新

  • donte1234567 2016-04-21 02:21
    关注

    I already found out the answer. Thanks to @akrabat

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>Slim 3</title>
            <link rel="stylesheet" href="http://yegor256.github.io/tacit/tacit.min.css">
        </head>
        <body>
            <h1>Upload a file</h1>
            <form method="POST" action="/upload" enctype="multipart/form-data">
                <label>Select file to upload:</label>
                <input type="file" name="newfile">
                <button type="submit">Upload</button>
            </form>
        </body>
    </html>

    $app->post('/upload', function ($request, $response, $args) {
        $files = $request->getUploadedFiles();
        if (empty($files['newfile'])) {
            throw new Exception('Expected a newfile');
        }
    
        $newfile = $files['newfile'];
        // do something with $newfile
    });

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100