我使用 PHP/Silex 来做一个 API。我所有的代码工作都集中在一条路上...这是我的索引.php我的API代码,我遇到了问题:
require_once __DIR__.'/../vendor/autoload.php';
header("Access-Control-Allow-Origin: *");
$app = new Silex'Application();
use Symfony'Component'HttpFoundation'Request;
use Symfony'Component'HttpFoundation'ParameterBag;
use Symfony'Component'HttpFoundation'File'UploadedFile;
$app->post('/upload', function (Request $request) use ($app)
{
$file = $request->files->get('upload');
if ($file == NULL)
{
$send = json_encode(array("status" => "Fail"));
return $app->json($send, 500);
}
else
{
$file->move(__DIR__.'/../files', $file->getClientOriginalName());
$send = json_encode(array("status" => "Ok"));
return $app->json($send, 200);
}
});
$app->run();
当我评论此行时,程序返回状态$file->move(__DIR__.'/../files', $file->getClientOriginalName());
,但如果我让这一行。我有一个text/html
作为回应,我们可以阅读,
..Whoops, looks like something went wrong
FileException in File.php line 134:
Unable to create the "/var/www/api-picShary/web/../files" directory
in File.php line 134
at File->getTargetFile('/var/www/api-picShary/web/../files', 'awesome.png') in UploadedFile.php line 239
at UploadedFile->move('/var/www/api-picShary/web/../files', 'awesome.png') in index.php line 79
at {closure}( object( Request))
at call_user_func_array( object( Closure), array( object( Request))) in HttpKernel.php line 145
at HttpKernel->handleRaw( object( Request), '1') in HttpKernel.php line 66
at HttpKernel->handle( object( Request), '1', true) in Application.php line 543
at Application->handle( object( Request)) in Application.php line 520
在索引中的应用程序>run().php第86行...
我使用表格发送我的文件:
< form action="" method="post" enctype="multipart/form-data">
< input type="file" name="upload">
< input type="submit">
< /form>
问题有php.ini,我不得不更改upload_max_filesizepost_max_size
/etc/php5/cli/conf.d/php.ini
工作
结束