本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request::getFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getFiles方法的具体用法?PHP Request::getFiles怎么用?PHP Request::getFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\PhpEnvironment\Request
的用法示例。
在下文中一共展示了Request::getFiles方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadImageAction
public function uploadImageAction()
{
$this->checkAuth();
$request = $this->getRequest();
if ($request->isPost()) {
// File upload input
$file = new FileInput('avatar');
// Special File Input type
$file->getValidatorChain()->attach(new Validator\File\UploadFile());
$file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => './public/files/users/avatar/origin/', 'use_upload_name' => true, 'randomize' => true)));
// Merge $_POST and $_FILES data together
$request = new Request();
$postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$inputFilter = new InputFilter();
$inputFilter->add($file)->setData($postData);
if ($inputFilter->isValid()) {
// FileInput validators are run, but not the filters...
$data = $inputFilter->getValues();
// This is when the FileInput filters are run.
$avatar = basename($data['avatar']['tmp_name']);
$this->databaseService->updateAvatar($this->user->id, $avatar);
$this->user->avatar = $avatar;
} else {
// error
}
}
return $this->redirect()->toRoute('profile');
}
示例2: upload
/**
*
* 文件上传处理
* @param Request $request
* @return bool|string
* @throws \Exception
*/
public function upload(Request $request)
{
if (!$request instanceof Request) {
throw new \Exception(BaseConst::UPLOAD_PARAMETER_ERROR_MSG, BaseConst::UPLOAD_PARAMETER_ERROR);
}
if (!$this->targetAbs) {
$this->setTargetDir();
}
$files = $request->getFiles()->toArray();
if (empty($files)) {
throw new \Exception(BaseConst::UPLOAD_PARAMETER_ERROR_MSG, BaseConst::UPLOAD_PARAMETER_ERROR);
}
$transer = new \Zend\File\Transfer\Adapter\Http();
$filters = array();
$result = array();
// 传输文件准备
foreach ($files as $k => $v) {
$tmp[] = $v['name'];
$ext = strstr($v['name'], '.');
$tmpName = strstr($v['name'], '.', true);
$filters[] = new \Zend\Filter\File\Rename(array('target' => $this->targetAbs . md5($tmpName) . $ext, "randomize" => true));
// 判断文件后缀是否合法
if (!$this->checkAllowType($ext)) {
throw new \Exception(BaseConst::UPLOAD_FILE_EXT_NOT_VALID_MSG, BaseConst::UPLOAD_FILE_EXT_NOT_VALID);
}
}
// 传输文件
$transer->setFilters($filters);
$transer->receive($tmp);
foreach ($files as $k => $v) {
$fileInfo = $transer->getFileInfo($k);
$data = array('name' => $fileInfo[$k]['name'], 'path' => $this->targetRel . $fileInfo[$k]['name'], 'type' => $fileInfo[$k]['type']);
$ext = strstr($fileInfo[$k]['name'], '.');
$tmpFileName = strstr($fileInfo[$k]['name'], '.', true);
// 生成缩略图
if ($this->ifThumb) {
$thumbInfo = $this->makeThumb($this->targetAbs . $fileInfo[$k]['name'], $this->targetAbs . $tmpFileName . $this->thumbW . 'X' . $this->thumbH . $ext, $this->thumbW, $this->thumbH);
$data['thumb'] = $thumbInfo;
}
// 加水印
if ($this->ifWaterMark) {
$this->makeWatermark($this->targetAbs . $fileInfo[$k]['name'], 6, '', $this->waterText, $_SERVER['DOCUMENT_ROOT'] . '/STXIHEI.TTF', $this->waterPct);
}
$result[] = $data;
}
if ($result) {
return json_encode($result);
} else {
return false;
}
}
示例3: createFromRequest
public static function createFromRequest(BaseRequest $request)
{
$new = static::fromString($request->toString());
$new->setQuery($request->getQuery());
$new->setPost($request->getPost());
$new->setCookies($request->getCookie());
$new->setFiles($request->getFiles());
$new->setServer($request->getServer());
$new->setContent($request->getContent());
$new->setEnv($request->getEnv());
$headers = $request->getHeaders();
$new->setHeaders($headers);
return $new;
}
示例4: testRetrievingASingleValueForParameters
public function testRetrievingASingleValueForParameters()
{
$request = new Request();
$p = new \Zend\Stdlib\Parameters(array('foo' => 'bar'));
$request->setQuery($p);
$request->setPost($p);
$request->setFiles($p);
$request->setServer($p);
$request->setEnv($p);
$this->assertSame('bar', $request->getQuery('foo'));
$this->assertSame('bar', $request->getPost('foo'));
$this->assertSame('bar', $request->getFiles('foo'));
$this->assertSame('bar', $request->getServer('foo'));
$this->assertSame('bar', $request->getEnv('foo'));
$headers = new Headers();
$h = new GenericHeader('foo', 'bar');
$headers->addHeader($h);
$request->setHeaders($headers);
$this->assertSame($headers, $request->getHeaders());
$this->assertSame($h, $request->getHeaders()->get('foo'));
$this->assertSame($h, $request->getHeader('foo'));
}
示例5: addfileAction
public function addfileAction()
{
$this->checkAuth();
$request = $this->getRequest();
if ($request->isPost()) {
$file_attach = new FileAttachment();
$file_attach->user_create = $this->auth->getIdentity()->id;
$file_attach->date_create = date('Y-m-d H:i:s');
$file_attach->last_date = $file_attach->date_create;
$file_attach->last_user = $this->auth->getIdentity()->id;
// info pay
$file_attach->task_id = $request->getPost('task_id');
$file_attach->permission_option = $request->getPost('permission_option');
if ($this->isLevel2() != true) {
$permission = $this->databaseService->getPermissionUser($file_attach->task_id, $file_attach->user_create);
if ($permission == Config::FILE_PERMISSION_ERROR) {
return new JsonModel(array());
}
if ($permission == Config::FILE_PERMISSION_CUSTUMER) {
$file_attach->permission_option = Config::FILE_PERMISSION_CUSTUMER;
}
if ($permission == Config::FILE_PERMISSION_PROVIDER) {
$file_attach->permission_option = Config::FILE_PERMISSION_PROVIDER;
}
}
// File upload input
$file = new FileInput('file_name');
// Special File Input type
$file->getValidatorChain()->attach(new Validator\File\UploadFile());
$file->getFilterChain()->attach(new Filter\File\RenameUpload(array('target' => '.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id, 'use_upload_name' => true, 'randomize' => true)));
if (!file_exists('.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id)) {
mkdir('.' . Config::FILE_ATTACHMENT_PATH . $file_attach->task_id, 0700, true);
}
// Merge $_POST and $_FILES data together
$request = new Request();
$postData = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$inputFilter = new InputFilter();
$inputFilter->add($file)->setData($postData);
if ($inputFilter->isValid()) {
// FileInput validators are run, but not the filters...
$data = $inputFilter->getValues();
// This is when the FileInput filters are run.
$file_attach->real_name = basename($data['file_name']['tmp_name']);
$file_attach->file_name = basename($data['file_name']['name']);
$result = $this->databaseService->addFileAttachment($file_attach);
$file_attach->id = $result->getGeneratedValue();
$this->databaseService->addFileLog($this->auth->getIdentity()->id, $file_attach, Config::PAY_INFO_COMMON);
}
}
return new JsonModel(array());
}
示例6: editAction
public function editAction()
{
$this->accessRights(17);
//Accept Parent Module, Return Main Menu Lists with Active Menu Indicator
$this->childModuleAccessRights(17, 'edit');
//Accept Child Module ID & it's Actions: add, edit, view, disable
//$msgs means message, it will show if data had been changed.
$msgs = '';
//get the id from parameter
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('media_profile', array('action' => 'add', 'access_rights' => $this->getSubModuleAccessRights(17)));
}
try {
$media_profile = $this->getMediaProfileTable()->getMediaProfile($this->serviceLocator(), $id);
$media_profile_education = $this->getMediaProfileTable()->getMediaProfileEducation($this->serviceLocator(), $id);
$media_profile_career = $this->getMediaProfileTable()->getMediaProfileCareer($this->serviceLocator(), $id);
} catch (\Exception $ex) {
return $this->redirect()->toRoute('media_profile', array('action' => 'index', 'access_rights' => $this->getSubModuleAccessRights(17)));
}
//instantiate the Media Profile's Form
//populate the data
$form_media_profile = new MediaProfileForm($this->serviceLocator());
$form_media_profile->get('relation_id')->setAttribute('options', $this->optionRelations());
$form_media_profile->get('additional_position_id[]')->setAttribute('options', $this->optionPositions());
$form_media_profile->get('additional_beat_id[]')->setAttribute('options', $this->optionBeats());
$form_media_profile->get('additional_section_id[]')->setAttribute('options', $this->optionSections());
$form_media_profile->get('additional_radio_station_id[]')->setAttribute('options', $this->optionRadioStations());
$form_media_profile->get('additional_tv_channel_id[]')->setAttribute('options', $this->optionTVChannels());
$form_media_profile->get('additional_source_id[]')->setAttribute('options', $this->optionSources());
$form_media_profile->get('submit')->setAttribute('value', 'Save');
$form_media_profile->setData($media_profile);
//remove inputfilter for select element due to conflict
$formInputFilter = $form_media_profile->getInputFilter();
$formInputFilter->remove('year[]');
$formInputFilter->remove('educ_course[]');
$formInputFilter->remove('educ_school[]');
$formInputFilter->remove('additional_year[]');
$formInputFilter->remove('additional_educ_course[]');
$formInputFilter->remove('additional_educ_school[]');
//remove inputfilter for select element due to conflict
//CAREER
$formInputFilter = $form_media_profile->getInputFilter();
$formInputFilter->remove('from[]');
$formInputFilter->remove('to[]');
$formInputFilter->remove('position_id[]');
$formInputFilter->remove('beat_id[]');
$formInputFilter->remove('section_id[]');
$formInputFilter->remove('source_id[]');
$formInputFilter->remove('circulation[]');
$formInputFilter->remove('other_affiliation[]');
$formInputFilter->remove('additional_from[]');
$formInputFilter->remove('additional_to[]');
$formInputFilter->remove('additional_position_id[]');
$formInputFilter->remove('additional_beat_id[]');
$formInputFilter->remove('additional_section_id[]');
$formInputFilter->remove('additional_source_id[]');
$formInputFilter->remove('additional_circulation[]');
$formInputFilter->remove('additional_other_affiliation[]');
//check if the data request is post
//update the data
$request = $this->getRequest();
if ($request->isPost()) {
//prepare audit trail parameters
$from = (array) $media_profile;
$to = $this->getRequest()->getPost()->toArray();
$diff = array_diff_assoc($to, $from);
unset($diff['submit'], $diff['media_profles_id'], $diff['media_profile_careers_id'], $diff['media_profile_educations_id'], $diff['year'], $diff['educ_course'], $diff['educ_school'], $diff['additional_year'], $diff['additional_educ_course'], $diff['additional_educ_school'], $diff['from'], $diff['to'], $diff['media_profile_type'], $diff['position_id'], $diff['beat_id'], $diff['section_id'], $diff['circulation'], $diff['source_id'], $diff['other_affiliation'], $diff['additional_from'], $diff['additional_to'], $diff['additional_media_profile_type'], $diff['additional_position_id'], $diff['additional_beat_id'], $diff['additional_section_id'], $diff['additional_circulation'], $diff['additional_source_id'], $diff['additional_other_affiliation']);
$changes = $this->prepare_modified_data($from, $to, $diff);
//end audit trail parameters
$media_profile = new MediaProfile();
$post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$form_media_profile->setData($post);
//uploading file
$request = new Request();
//request to get the file
$files = $request->getFiles();
//get the details of uploading file
if ($files['photo']['name']) {
$filter = new \Zend\Filter\File\Rename(array("target" => "./public/img/" . $files['photo']['name'], "overwrite" => true));
$filter->filter($files['photo']);
//resize image
$imagine = $this->getImagineService();
$size = new \Imagine\Image\Box(150, 150);
$mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
$image = $imagine->open('./public/img/' . $files['photo']['name']);
$image->thumbnail($size, $mode)->save('./public/img/' . $files['photo']['name']);
//resize image
$imagine = $this->getImagineService();
$image = $imagine->open('./public/img/' . $files['photo']['name']);
$image->resize(new Box(150, 150))->save('./public/img/' . $files['photo']['name']);
}
$media_profile->exchangeArray($post);
if (isset($_POST['year']) || isset($_POST['educ_course']) || isset($_POST['educ_school']) || isset($_POST['additional_year']) || isset($_POST['additional_educ_course']) || !empty($to) || isset($_POST['additional_educ_school'])) {
$this->getMediaProfileTable()->saveProfileEducation($this->serviceLocator());
}
if (isset($_POST['from']) || isset($_POST['to']) || isset($_POST['media_profile_type']) || isset($_POST['position_id']) || isset($_POST['beat_id']) || isset($_POST['section_id']) || isset($_POST['source_id']) || isset($_POST['circulation']) || isset($_POST['other_affiliation']) || isset($_POST['additional_from']) || isset($_POST['additional_to']) || isset($_POST['additional_media_profile_type']) || isset($_POST['additional_position_id']) || isset($_POST['additional_beat_id']) || isset($_POST['additional_section_id']) || isset($_POST['additional_source_id']) || isset($_POST['additional_circulation']) || isset($_POST['additional_other_affiliation'])) {
$this->getMediaProfileTable()->saveProfileCareer($this->serviceLocator());
}
$this->getMediaProfileTable()->saveMediaProfile($media_profile);
//.........这里部分代码省略.........
示例7: saveNewsDetail
public function saveNewsDetail(AdapterInterface $adapter, News $news)
{
//media outfits
//1 = online
//4 = print local
//5 = print national
//6 = radio
//7 = tv
$news_header_id = $_POST['news_header_id'];
$media_outfit_id = $_POST['media_outfit_id'];
$news_detail_id = $_POST['news_detail_id'];
if ($news_header_id == '') {
//insert new online news
if ($media_outfit_id == 1) {
$article_type_id = $_POST['article_type_id'] == '' ? null : $_POST['article_type_id'];
$section_id = $_POST['section_id'] == '' ? null : $_POST['section_id'];
$page = $_POST['page'];
$source_id = $_POST['source_id'] == '' ? null : $_POST['source_id'];
$initiated_by = $_POST['initiated_by'] == '' ? null : $_POST['initiated_by'];
$media_profile_id = $_POST['media_profile_id'] == '' ? null : $_POST['media_profile_id'];
$section_editor_id = $_POST['section_editor_id'] == '' ? null : $_POST['section_editor_id'];
$attachment = '';
$request = new Request();
//request to get the file
$files = $request->getFiles();
//get the details of uploading file
if ($news->attachments['name']) {
$request = new Request();
//request to get the file
$files = $request->getFiles();
//get the details of uploading file
$file = pathinfo($files['attachments']['name']);
$filename = str_replace(" ", ".", uniqid() . '.' . $file['extension']);
$this->saveAttachment($files, $filename);
$attachment = $filename;
}
$sub_kind = !isset($_POST['sub_kind']) ? -1 : $_POST['sub_kind'];
//insert new News detail
$this->adapter = $adapter;
$sql = "INSERT INTO news_details (`article_type_id`,`section_id`, `page`, `source_id`, `section_editor_id`, `initiated_by`, `media_profile_id`, `attachment`, `sub_kind`) VALUES (?,?,?,?,?,?,?,?,?);SELECT news_details_id FROM news_details WHERE news_details_id=LAST_INSERT_ID();";
$statement = $this->adapter->createStatement($sql, array($article_type_id, $section_id, $page, $source_id, $section_editor_id, $initiated_by, $media_profile_id, $attachment, $sub_kind));
$result = $statement->execute();
} else {
if ($media_outfit_id == 4) {
//insert new print local
$article_type_id = $_POST['article_type_id'] == '' ? null : $_POST['article_type_id'];
$section_id = $_POST['section_id'] == '' ? null : $_POST['section_id'];
$page = $_POST['page'] == '' ? null : $_POST['page'];
$source_id = $_POST['source_id'] == '' ? null : $_POST['source_id'];
$section_editor_id = $_POST['section_editor_id'] == '' ? null : $_POST['section_editor_id'];
$initiated_by = $_POST['initiated_by'] == '' ? null : $_POST['initiated_by'];
$media_profile_id = $_POST['media_profile_id'] == '' ? null : $_POST['media_profile_id'];
$geography = $_POST['geography'] == '' ? null : $_POST['geography'];
$region = $_POST['region'] == '' ? null : $_POST['region'];
$province = $_POST['province'] == '' ? null : $_POST['province'];
$attachment = '';
if ($news->attachments['name']) {
$request = new Request();
//request to get the file
$files = $request->getFiles();
//get the details of uploading file
$file = pathinfo($files['attachments']['name']);
$filename = str_replace(" ", ".", uniqid() . '.' . $file['extension']);
$this->saveAttachment($files, $filename);
$attachment = $filename;
}
$this->adapter = $adapter;
$sql = "INSERT INTO news_details (`article_type_id`,`section_id`, `page`, `source_id`, `section_editor_id`, `initiated_by`, `media_profile_id`, `attachment`, `geography`, `region`, `province`) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
$statement = $this->adapter->createStatement($sql, array($article_type_id, $section_id, $page, $source_id, $section_editor_id, $initiated_by, $media_profile_id, $attachment, $geography, $region, $province));
$result = $statement->execute();
} else {
if ($media_outfit_id == 5) {
//insert new print national
$article_type_id = $_POST['article_type_id'] == '' ? null : $_POST['article_type_id'];
$section_id = $_POST['section_id'] == '' ? null : $_POST['section_id'];
$page = $_POST['page'] == '' ? null : $_POST['page'];
$source_id = $_POST['source_id'] == '' ? null : $_POST['source_id'];
$initiated_by = $_POST['initiated_by'] == '' ? null : $_POST['initiated_by'];
$media_profile_id = $_POST['media_profile_id'] == '' ? null : $_POST['media_profile_id'];
$section_editor_id = $_POST['section_editor_id'] == '' ? null : $_POST['section_editor_id'];
$attachment = '';
if ($news->attachments['name']) {
$request = new Request();
//request to get the file
$files = $request->getFiles();
//get the details of uploading file
$file = pathinfo($files['attachments']['name']);
$filename = str_replace(" ", ".", uniqid() . '.' . $file['extension']);
$this->saveAttachment($files, $filename);
$attachment = $filename;
}
//save print local
$this->adapter = $adapter;
$sql = "INSERT INTO news_details (`article_type_id`,`section_id`, `page`, `source_id`, `section_editor_id`, `initiated_by`, `media_profile_id`, `attachment`) VALUES (?,?,?,?,?,?,?,?)";
$statement = $this->adapter->createStatement($sql, array($article_type_id, $section_id, $page, $source_id, $section_editor_id, $initiated_by, $media_profile_id, $attachment));
$result = $statement->execute();
} else {
if ($media_outfit_id == 6) {
//insert new radio
$radio_program_id = $_POST['radio_program_id'] == '' ? null : $_POST['radio_program_id'];
//.........这里部分代码省略.........
示例8: handleForm
/**
* Handles a given form for the add and edit action
* @return array Array for the view, containing the form and maybe id and errors
*/
private function handleForm(Request &$request, NewsCategoryForm &$form, NewsCategory &$nc, $id = 0)
{
$form->setInputFilter($nc->getInputFilter());
$post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$form->setData($post);
if ($form->isValid()) {
$nc->exchangeArray($post);
$old = $this->getNewsCategoryTable()->getNewsCategoryBy(['id' => $id]);
if ($this->getNewsCategoryTable()->getNewsCategoryBy(['name' => $nc->getName()]) && ($id === 0 || $nc->getName() !== $old->getName())) {
$errors['name'] = ['exists' => 'A category with this name already exists'];
$form->get('name')->setMessages($errors);
if (!$id) {
return ['form' => $form, 'errors' => $errors];
}
return ['form' => $form, 'errors' => $errors, 'id' => $id];
}
$size = new Size(['min' => 20, 'max' => 20000]);
$adapter = new Http();
$adapter->setValidators([$size], $post['path']);
//Only throw error if a new category is created. New Categories need an image
if (!$adapter->isValid() && $id === 0) {
$errors = $adapter->getMessages();
return ['form' => $form, 'errors' => $errors];
}
$dir = getcwd() . '/public/news_cat/';
//A file was given, so it will be saved on the server
if ($adapter->isValid()) {
if (!file_exists($dir)) {
mkdir($dir);
}
$pic = $post['path'];
$file = file_get_contents($pic['tmp_name']);
file_put_contents($dir . $nc->getName() . '.png', $file);
} else {
//No new file was given, so update the filename to the new name
rename($dir . $old->getName() . '.png', $dir . $nc->getName() . '.png');
}
$this->getNewsCategoryTable()->saveNewsCategory($nc);
return $this->redirect()->toRoute('newscategory');
}
$errors = $form->getMessages();
if ($id) {
return ['form' => $form, 'errors' => $errors, 'id' => $id];
}
return ['form' => $form, 'errors' => $errors];
}