note 119643 added to features.file-upload.post-method

From: Date: Sun, 24 Jul 2016 06:44:22 +0000
Subject: note 119643 added to features.file-upload.post-method
Groups: php.notes 
Request: Send a blank email to php-notes+get-206090@lists.php.net to get a copy of this message
Do not use Coreywelch or Daevid's way, because their methods can handle only within two-dimensional structure. $_FILES can consist of any hierarchy, such as 3d or 4d structure. The following example form breaks their codes: <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="files[x][y][z]"> <input type="submit"> </form> As the solution, you should use PSR-7 based zendframework/zend-diactoros. GitHub: https://github.com/zendframework/zend-diactoros Example: <?php use Psr\Http\Message\UploadedFileInterface; use Zend\Diactoros\ServerRequestFactory; $request = ServerRequestFactory::fromGlobals(); if ($request->getMethod() !== 'POST') { http_response_code(405); exit('Use POST method.'); } $uploaded_files = $request->getUploadedFiles(); if ( !isset($uploaded_files['files']['x']['y']['z']) || !$uploaded_files['files']['x']['y']['z'] instanceof UploadedFileInterface ) { http_response_code(400); exit('Invalid request body.'); } $file = $uploaded_files['files']['x']['y']['z']; if ($file->getError() !== UPLOAD_ERR_OK) { http_response_code(400); exit('File uploading failed.'); } $file->moveTo('/path/to/new/file'); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 58.146.6.197 ---- Manual Page -- http://php.net/manual/en/features.file-upload.post-method.php Edit -- https://master.php.net/note/edit/119643 Del: integrated -- https://master.php.net/note/delete/119643/integrated Del: useless -- https://master.php.net/note/delete/119643/useless Del: bad code -- https://master.php.net/note/delete/119643/bad+code Del: spam -- https://master.php.net/note/delete/119643/spam Del: non-english -- https://master.php.net/note/delete/119643/non-english Del: in docs -- https://master.php.net/note/delete/119643/in+docs Del: other reasons-- https://master.php.net/note/delete/119643 Reject -- https://master.php.net/note/reject/119643 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206090) next »