你好我在苗条3框架(移动设备Api)的新功能我想知道如何将图像上传到服务器,例如e seacrh没有找到太多,这是我的代码,但它不起作用。任何帮助将非常感谢。
$app->post('/photo', function ($request, $response) use ($app) {
$files = $request->getUploadedFiles();
if (empty($files['newfile'])) {
throw new Exception('Expected a newfile');
}
$newfile = $files['newfile'];
if ($newfile->getError() === UPLOAD_ERR_OK) {
$uploadFileName = $newfile->getClientFilename();
$newfile->moveTo("../photos/");
}
});
它给我的错误
<h1>Slim Application Error</h1>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div>
<strong>Type:</strong> Error
</div>
<div>
<strong>Message:</strong> Call to a member function getError() on null
</div>
<div>
<strong>File:</strong> /home/bitstudi/public_html/api_pricegram/public/index.php
</div>
<div>
<strong>Line:</strong> 155
</div>
<h2>Trace</h2>
#0 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array) #1 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array) #2 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/Route.php(344): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array) #3 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response)) #4 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response)) #5 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response)) #6 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response)) #7 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response)) #8 /home/bitstudi/public_html/api_pricegram/vendor/slim/slim/Slim/App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response)) #9 /home/bitstudi/public_html/api_pricegram/public/index.php(161): Slim\App->run() #10 {main}
答案 0 :(得分:3)
@Temporal