php - Slim Framework 3 Upload -


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 application not run because of following error:  details  type: runtimeexception message: error moving uploaded file hss.png /home/xxx/web/slim3/app/../log file: /home/xxx/web/slim3/vendor/slim/slim/slim/http/uploadedfile.php line: 237 

i found out answer. @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 file</h1>          <form method="post" action="/upload" enctype="multipart/form-data">              <label>select file 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 newfile');      }        $newfile = $files['newfile'];      // $newfile  });


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -