Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我试图上传一个文件,API Silex_Php_Html_Post_Apache2_Silex - Fatal编程技术网

Php 我试图上传一个文件,API Silex

Php 我试图上传一个文件,API Silex,php,html,post,apache2,silex,Php,Html,Post,Apache2,Silex,我使用PHP/Silex做API。 我所有的代码工作除了一条路。。。 下面是API代码的index.php,我遇到了一个问题: require_once __DIR__.'/../vendor/autoload.php'; header("Access-Control-Allow-Origin: *"); $app = new Silex\Application(); use Symfony\Component\HttpFoundation\Request; use Symfony\Com

我使用PHP/Silex做API。 我所有的代码工作除了一条路。。。 下面是API代码的index.php,我遇到了一个问题:

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(\uuuu DIR\uuu.'/../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
在index.php第86行的Application->run()处

我使用表格发送我的文件:

< form action="" method="post" enctype="multipart/form-data">
< input type="file" name="upload">
< input type="submit">
< /form>

问题出在php.ini上,我不得不更改上传的最大文件大小 贴纸最大尺寸

/etc/php5/cli/conf.d/php.ini

工作


结束

您是否确保Web服务器用户可以写入文件目录?您也可以尝试启用调试模式(
$app['debug']=true;
),您将收到一条更好的错误消息。@mTorres是的,他可以(当然是chmod 777和chown www data),调试模式是启用的,但没有任何更改…@mtorresedit:I重新启动我的服务器,$app['debug']工作