我有一个Symfony2端点需要接受带有一些文本参数的post请求和一个由第三方程序提供的zip文件。为了快速开发,我开始只使用Chrome POST插件来欺骗发送表单数据。使用该方法时,我能够正确检索文件。
但是,当我切换到第三方Windows应用程序上传报告时,我无法再检索该文件。我现在得到mimeType' => 'application/octet-stream'
,文件大小为0,而不是确定它是一个zip文件。
我在以下链接中阅读,我需要确保我的post_max_size和upload_max_filesize足够大以处理该文件。 Can't upload image with mime-type "application/octet-stream" in Symfony2
我不想乱搞,所以我把它设置为100mb,但仍然没有运气。
以下是请求的转储:
[2016-08-24 10:15:48] app.INFO: Request dump: Symfony\Component\HttpFoundation\Request::__set_state(array( 'attributes' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( '_format' => 'xml', '_controller' => 'Company\\Bundle\\CompanyBundle\\Controller\\DefaultController::cloudTransferReport', '_route' => 'hg_cloudtransfer_report', '_route_params' => array ( '_format' => 'xml', ), '_method' => Sensio\Bundle\FrameworkExtraBundle\Configuration\Method::__set_state(array( 'methods' => array ( 0 => 'POST', 1 => 'GET', ), )), ), )), 'request' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( 'submitter' => 'hgis', 'version' => '5.1.26.0', 'userName' => 'admin', 'password' => 'kitten', ), )), 'query' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( ), )), 'server' => Symfony\Component\HttpFoundation\ServerBag::__set_state(array( 'parameters' => array ( 'REDIRECT_HTTPS' => 'on', 'REDIRECT_SSL_TLS_SNI' => 'example.com', 'REDIRECT_STATUS' => '200', 'HTTPS' => 'on', 'SSL_TLS_SNI' => 'example.com', 'CONTENT_TYPE' => 'multipart/form-data, boundary=AaBbCcDdHhGg40', 'HTTP_USER_AGENT' => 'Some software v 5.1.26.0', 'HTTP_HOST' => 'example.com', 'CONTENT_LENGTH' => '3592731', 'HTTP_CACHE_CONTROL' => 'no-cache', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.4.18 (Unix) PHP/5.5.36 LibreSSL/2.2.7', 'SERVER_NAME' => 'example.com', 'SERVER_ADDR' => '192.168.1.100', 'SERVER_PORT' => '443', 'REMOTE_ADDR' => '192.168.1.223', 'DOCUMENT_ROOT' => '/Users/user/Documents/symphony/cpsrecall/web', 'REQUEST_SCHEME' => 'https', 'CONTEXT_PREFIX' => '', 'CONTEXT_DOCUMENT_ROOT' => '/Users/user/Documents/symphony/cpsrecall/web', 'SERVER_ADMIN' => 'chris@yourcontactpoint.com', 'SCRIPT_FILENAME' => '/Users/user/Documents/symphony/cpsrecall/web/app.php', 'REMOTE_PORT' => '51248', 'REDIRECT_URL' => '/hg/cloudtransfer/upload-report', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'POST', 'QUERY_STRING' => '', 'REQUEST_URI' => '/hg/cloudtransfer/upload-report', 'SCRIPT_NAME' => '/app.php', 'PHP_SELF' => '/app.php', 'REQUEST_TIME_FLOAT' => 1472055346.6129999, 'REQUEST_TIME' => 1472055346, ), )), 'files' => Symfony\Component\HttpFoundation\FileBag::__set_state(array( 'parameters' => array ( 'file1' => Symfony\Component\HttpFoundation\File\UploadedFile::__set_state(array( 'test' => false, 'originalName' => '00000003-1.zip', 'mimeType' => 'application/octet-stream', 'size' => 0, 'error' => 1, )), ), )), 'cookies' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( ), )), 'headers' => Symfony\Component\HttpFoundation\HeaderBag::__set_state(array( 'headers' => array ( 'content-type' => array ( 0 => 'multipart/form-data, boundary=AaBbCcDdHhGg40', ), 'user-agent' => array ( 0 => 'Some software v 5.1.26.0', ), 'host' => array ( 0 => 'example.com', ), 'content-length' => array ( 0 => '3592731', ), 'cache-control' => array ( 0 => 'no-cache', ), 'x-php-ob-level' => array ( 0 => 1, ), ), 'cacheControl' => array ( 'no-cache' => true, ), )), 'content' => '', 'languages' => NULL, 'charsets' => NULL, 'encodings' => NULL, 'acceptableContentTypes' => NULL, 'pathInfo' => '/hg/cloudtransfer/upload-report', 'requestUri' => '/hg/cloudtransfer/upload-report', 'baseUrl' => '', 'basePath' => NULL, 'method' => 'POST', 'format' => NULL, 'session' => Symfony\Component\HttpFoundation\Session\Session::__set_state(array( 'storage' => Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::__set_state(array( 'bags' => array ( 'attributes' => Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag::__set_state(array( 'name' => 'attributes', 'storageKey' => '_sf2_attributes', 'attributes' => array ( ), )), 'flashes' => Symfony\Component\HttpFoundation\Session\Flash\FlashBag::__set_state(array( 'name' => 'flashes', 'flashes' => array ( ), 'storageKey' => '_sf2_flashes', )), ), 'started' => false, 'closed' => false, 'saveHandler' => Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::__set_state(array( 'handler' => SessionHandler::__set_state(array( )), 'wrapper' => true, 'active' => false, 'saveHandlerName' => 'files', )), 'metadataBag' => Symfony\Component\HttpFoundation\Session\Storage\MetadataBag::__set_state(array( 'name' => '__metadata', 'storageKey' => '_sf2_meta', 'meta' => array ( 'c' => 0, 'u' => 0, 'l' => 0, ), 'lastUsed' => NULL, 'updateThreshold' => '0', )), )), 'flashName' => 'flashes', 'attributeName' => 'attributes', )), 'locale' => NULL, 'defaultLocale' => 'en', )) [] []
对于那些不想阅读那么长的大行的人来说,这里只是FileBag:
[2016-08-24 10:15:48] app.INFO: file1dump: Symfony\Component\HttpFoundation\File\UploadedFile::__set_state(array( 'test' => false, 'originalName' => '00000003-1.zip', 'mimeType' => 'application/octet-stream', 'size' => 0, 'error' => 1, )) [] []
这是我的代码应该抓取文件,但也许我错了:
public function cloudTransferReport(Request $request)
{
$logger = $this->get('logger');
$em = $this->getDoctrine()->getManager();
$data = $request->request;
$files = $request->files;
$submitter = $data->get('submitter');
$version = $data->get('version');
$memberName = $data->get('userName');
$password = $data->get('password');
$file1 = $files->get('file1');
$logger->info("file string: " . var_export($stuff, true));
$logger->info("file1dump: " . var_export($file1, true));
如果您需要来自该控制器的更多代码,请告诉我,但我认为至少应该能够将该文件存储在内存中。
答案 0 :(得分:0)
Ok Mac用户遇到这样的问题,特别是那些使用过自制软件的用户,可能安装或不安装多个版本的PHP。
您的计算机上可能有多个php.ini文件。我运行了php --ini
,它提出了Loaded Configuration File: /usr/local/etc/php/5.6/php.ini
。这错了!
结束Apache正在使用的真实php.ini文件/etc/php.ini
,所以请,请不要浪费一整天的时间撞击键盘。确保您在Apache实际使用的文件中!就这些。我现在要爬到桌子底下哭了。