当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadedFile::getMaxFilesize方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getMaxFilesize方法的具体用法?PHP UploadedFile::getMaxFilesize怎么用?PHP UploadedFile::getMaxFilesize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\File\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::getMaxFilesize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Checks if the passed value is valid.
  *
  * @param UploadedFile   $file      The value that should be validated
  * @param Constraint     $constraint The constraint for the validation
  */
 public function validate($file, Constraint $constraint)
 {
     if (!in_array($file->getMimeType(), $this->mimeTypes)) {
         $this->context->buildViolation($constraint->messageMimeTypes)->atPath('file')->addViolation();
     }
     if ($file->getSize() > $file->getMaxFilesize()) {
         $this->context->buildViolation($constraint->messageMaxSize, array('%max_size%' => $file->getMaxFilesize()))->atPath('file')->addViolation();
     }
 }
开发者ID:open-orchestra,项目名称:open-orchestra-media-bundle,代码行数:15,代码来源:MediaFileValidator.php

示例2: maxUploadSize

 /**
  * @param int $size
  * @return int
  */
 public function maxUploadSize($size = null)
 {
     if (func_num_args() === 0) {
         return $this->maxUploadSize;
     }
     return $this->maxUploadSize = min((int) $size, UploadedFile::getMaxFilesize());
 }
开发者ID:pb199486,项目名称:Transit,代码行数:11,代码来源:UploadService.php

示例3: uploadImage

 /**
  * Upload an image.
  * @param \Symfony\Component\HttpFoundation\FileBag $p_file
  * @param string                                    $p_rootDir
  * @param string                                    $p_basePath
  * @param string                                    $p_folder
  * @param string                                    $p_path
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  * @throws \Exception
  */
 public function uploadImage(FileBag $p_file, $p_rootDir, $p_basePath, $p_folder, $p_path)
 {
     $arrExtension = array("gif", "jpeg", "jpg", "png");
     $folder = $this->obtainFolder($p_rootDir, $p_folder);
     $path = $this->obtainPath($p_basePath, $p_path);
     $response = new JsonResponse();
     // ------------------------- DECLARE ---------------------------//
     if ($p_file == null) {
         $response->setData(array("error" => "No file received."));
         return $response;
     }
     $file = $p_file->get("file");
     if ($file == null) {
         $response->setData(array("error" => "No file received."));
         return $response;
     }
     if ($file->getSize() > UploadedFile::getMaxFilesize()) {
         $response->setData(array("error" => "File too big."));
         return $response;
     }
     // Cheks image type.
     $extension = $file->guessExtension();
     $mime = $file->getMimeType();
     if (($mime == "image/gif" || $mime == "image/jpeg" || $mime == "image/pjpeg" || $mime == "image/x-png" || $mime == "image/png") && in_array($extension, $arrExtension)) {
         // Generates random name.
         $name = sha1(uniqid(mt_rand(), true)) . '.' . $file->guessExtension();
         // Save file in the folder.
         $file->move($folder, $name);
         $response->setData(array("link" => $path . '/' . $name));
         return $response;
     }
     $response->setData(array("error" => "File not supported."));
     return $response;
 }
开发者ID:WeCraftApps,项目名称:KMSFroalaEditorBundle,代码行数:44,代码来源:MediaManager.php

示例4: __construct

 /**
  * Constructor
  */
 public function __construct()
 {
     // Set default size equal to upload_max_filesize param in php.ini config
     $this->_uploadMaxSize = UploadedFile::getMaxFilesize();
     // Set default file name
     $this->_fileName = 'uploaded_on_' . date('Y-m-d_H-i-s');
 }
开发者ID:huydn8x,项目名称:symfony2-uploader,代码行数:10,代码来源:Uploader.php

示例5: checkUploadPostback

 /**
  * Checks the current request to see if it is a postback containing a file upload
  * for this particular widget.
  */
 protected function checkUploadPostback()
 {
     $fileName = null;
     try {
         $uploadedFile = Input::file('file_data');
         if (!is_object($uploadedFile)) {
             return;
         }
         $fileName = $uploadedFile->getClientOriginalName();
         // Don't rely on Symfony's mime guessing implementation, it's not accurate enough.
         // Use the simple extension validation.
         $allowedAssetTypes = Config::get('cms.allowedAssetTypes');
         if (!$allowedAssetTypes) {
             $allowedAssetTypes = $this->allowedAssetTypes;
         }
         $maxSize = UploadedFile::getMaxFilesize();
         if ($uploadedFile->getSize() > $maxSize) {
             throw new ApplicationException(Lang::get('cms::lang.asset.too_large', ['max_size ' => File::sizeToString($maxSize)]));
         }
         $ext = strtolower(pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_EXTENSION));
         if (!in_array($ext, $allowedAssetTypes)) {
             throw new ApplicationException(Lang::get('cms::lang.asset.type_not_allowed', ['allowed_types' => implode(', ', $allowedAssetTypes)]));
         }
         if (!$uploadedFile->isValid()) {
             throw new ApplicationException(Lang::get('cms::lang.asset.file_not_valid'));
         }
         $uploadedFile->move($this->getCurrentPath(), $uploadedFile->getClientOriginalName());
         die('success');
     } catch (Exception $ex) {
         $message = $fileName !== null ? Lang::get('cms::lang.asset.error_uploading_file', ['name' => $fileName, 'error' => $ex->getMessage()]) : $ex->getMessage();
         die($message);
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:37,代码来源:AssetList.php

示例6: indexAction

 public function indexAction(Request $request)
 {
     $configuration = [];
     $authenticationType = $this->container->getParameter('ilios_authentication.type');
     $configuration['type'] = $authenticationType;
     if ($authenticationType == 'shibboleth') {
         $loginPath = $this->container->getParameter('ilios_authentication.shibboleth.login_path');
         $url = $request->getSchemeAndHttpHost();
         $configuration['loginUrl'] = $url . $loginPath;
     }
     if ($authenticationType === 'cas') {
         $cas = $this->container->get('ilios_authentication.cas.manager');
         $configuration['casLoginUrl'] = $cas->getLoginUrl();
     }
     $configuration['locale'] = $this->container->getParameter('locale');
     $ldapUrl = $this->container->getParameter('ilios_core.ldap.url');
     if (!empty($ldapUrl)) {
         $configuration['userSearchType'] = 'ldap';
     } else {
         $configuration['userSearchType'] = 'local';
     }
     $configuration['maxUploadSize'] = UploadedFile::getMaxFilesize();
     $configuration['apiVersion'] = WebIndexFromJson::API_VERSION;
     $configuration['trackingEnabled'] = $this->container->getParameter('ilios_core.enable_tracking');
     if ($configuration['trackingEnabled']) {
         $configuration['trackingCode'] = $this->container->getParameter('ilios_core.tracking_code');
     }
     return new JsonResponse(array('config' => $configuration));
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:29,代码来源:ConfigController.php

示例7: filterFiles

 /**
  * Filters an array of files.
  *
  * This method created test instances of UploadedFile so that the move()
  * method can be called on those instances.
  *
  * If the size of a file is greater than the allowed size (from php.ini) then
  * an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
  *
  * @see UploadedFile
  *
  * @param array $files An array of files
  *
  * @return array An array with all uploaded files marked as already moved
  */
 protected function filterFiles(array $files)
 {
     $filtered = array();
     foreach ($files as $key => $value) {
         if (is_array($value)) {
             $filtered[$key] = $this->filterFiles($value);
         } elseif ($value instanceof UploadedFile) {
             if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) {
                 $filtered[$key] = new UploadedFile('', $value->getClientOriginalName(), $value->getClientMimeType(), 0, UPLOAD_ERR_INI_SIZE, true);
             } else {
                 $filtered[$key] = new UploadedFile($value->getPathname(), $value->getClientOriginalName(), $value->getClientMimeType(), $value->getClientSize(), $value->getError(), true);
             }
         }
     }
     return $filtered;
 }
开发者ID:itlessons,项目名称:php-application,代码行数:31,代码来源:Client.php

示例8: validate

 /**
  * {@inheritDoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if ($value instanceof UploadedFile && !$value->isValid()) {
         switch ($value->getError()) {
             case UPLOAD_ERR_INI_SIZE:
                 if ($constraint->maxSize) {
                     if (ctype_digit((string) $constraint->maxSize)) {
                         $maxSize = (int) $constraint->maxSize;
                     } elseif (preg_match('/^\\d++k$/', $constraint->maxSize)) {
                         $maxSize = $constraint->maxSize * 1024;
                     } elseif (preg_match('/^\\d++M$/', $constraint->maxSize)) {
                         $maxSize = $constraint->maxSize * 1048576;
                     } else {
                         throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $constraint->maxSize));
                     }
                     $maxSize = min(UploadedFile::getMaxFilesize(), $maxSize);
                 } else {
                     $maxSize = UploadedFile::getMaxFilesize();
                 }
                 $this->context->addViolation($constraint->uploadIniSizeErrorMessage, array('{{ limit }}' => $maxSize, '{{ suffix }}' => 'bytes'));
                 return;
             case UPLOAD_ERR_FORM_SIZE:
                 $this->context->addViolation($constraint->uploadFormSizeErrorMessage);
                 return;
             case UPLOAD_ERR_PARTIAL:
                 $this->context->addViolation($constraint->uploadPartialErrorMessage);
                 return;
             case UPLOAD_ERR_NO_FILE:
                 $this->context->addViolation($constraint->uploadNoFileErrorMessage);
                 return;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage);
                 return;
             case UPLOAD_ERR_CANT_WRITE:
                 $this->context->addViolation($constraint->uploadCantWriteErrorMessage);
                 return;
             case UPLOAD_ERR_EXTENSION:
                 $this->context->addViolation($constraint->uploadExtensionErrorMessage);
                 return;
             default:
                 $this->context->addViolation($constraint->uploadErrorMessage);
                 return;
         }
     }
     if (!is_scalar($value) && !$value instanceof FileObject && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
     if (!is_file($path)) {
         $this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path));
         return;
     }
     if (!is_readable($path)) {
         $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path));
         return;
     }
     if ($constraint->maxSize) {
         if (ctype_digit((string) $constraint->maxSize)) {
             $size = filesize($path);
             $limit = (int) $constraint->maxSize;
             $suffix = 'bytes';
         } elseif (preg_match('/^\\d++k$/', $constraint->maxSize)) {
             $size = round(filesize($path) / 1000, 2);
             $limit = (int) $constraint->maxSize;
             $suffix = 'kB';
         } elseif (preg_match('/^\\d++M$/', $constraint->maxSize)) {
             $size = round(filesize($path) / 1000000, 2);
             $limit = (int) $constraint->maxSize;
             $suffix = 'MB';
         } else {
             throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $constraint->maxSize));
         }
         if ($size > $limit) {
             $this->context->addViolation($constraint->maxSizeMessage, array('{{ size }}' => $size, '{{ limit }}' => $limit, '{{ suffix }}' => $suffix, '{{ file }}' => $path));
             return;
         }
     }
     if ($constraint->mimeTypes) {
         if (!$value instanceof FileObject) {
             $value = new FileObject($value);
         }
         $mimeTypes = (array) $constraint->mimeTypes;
         $mime = $value->getMimeType();
         $valid = false;
         foreach ($mimeTypes as $mimeType) {
             if ($mimeType === $mime) {
                 $valid = true;
                 break;
             }
             if ($discrete = strstr($mimeType, '/*', true)) {
                 if (strstr($mime, '/', true) === $discrete) {
                     $valid = true;
                     break;
                 }
//.........这里部分代码省略.........
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:101,代码来源:FileValidator.php

示例9: doRequestUpload

 /**
  * Upload file from the request
  *
  * @param  UploadedFile $file
  * @return Array $data Retrieve into the content of response
  * @throws BadRequestHttpException The file is too big
  */
 private function doRequestUpload(UploadedFile $file)
 {
     $tmpDirectory = $this->getApplication()->getTemporaryDir();
     $data = [];
     if (null !== $file) {
         if ($file->isValid()) {
             if ($file->getClientSize() <= $file->getMaxFilesize()) {
                 $data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
                 $file->move($tmpDirectory, $data['filename']);
                 $data['size'] = round($file->getClientSize() / 1024, 2);
                 if ($imageInfo = @getimagesize($data['path'])) {
                     if (isset($imageInfo[0]) && isset($imageInfo[1])) {
                         $data['width'] = $imageInfo[0];
                         $data['height'] = $imageInfo[1];
                     }
                 } else {
                     $data['width'] = 0;
                     $data['height'] = 0;
                 }
             } else {
                 throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
             }
         } else {
             throw new BadRequestHttpException($file->getErrorMessage());
         }
     }
     return $data;
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:35,代码来源:ResourceController.php

示例10: getFileProperties

 /**
  * @param UploadedFile $file
  *
  * @return array()
  */
 private function getFileProperties($file)
 {
     $properties = array();
     $properties['original_name'] = $file->getClientOriginalName();
     $properties['extension'] = $file->guessExtension();
     $properties['name'] = $this->getFileNameOrThumbnail($properties['original_name'], false);
     $properties['name_uid'] = $properties['original_name'];
     $properties['thumbnail_name'] = $this->getFileNameOrThumbnail($properties['original_name'], true);
     $properties['size'] = $file->getClientSize();
     $properties['maxfilesize'] = $file->getMaxFilesize();
     $properties['mimetype'] = $file->getMimeType();
     $properties['session'] = $this->session->getId();
     $properties['id_session'] = $this->id_session;
     $properties['temp_dir'] = $this->params['param_temp_path'] . '/' . $this->session->getId() . '/' . $properties['id_session'];
     return $properties;
 }
开发者ID:faparicior,项目名称:FARSymfony2Upload,代码行数:21,代码来源:FARSymfony2UploadLib.php

示例11: uploadedFileErrorProvider

 public function uploadedFileErrorProvider()
 {
     $tests = array(array(UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage'), array(UPLOAD_ERR_PARTIAL, 'uploadPartialErrorMessage'), array(UPLOAD_ERR_NO_FILE, 'uploadNoFileErrorMessage'), array(UPLOAD_ERR_NO_TMP_DIR, 'uploadNoTmpDirErrorMessage'), array(UPLOAD_ERR_CANT_WRITE, 'uploadCantWriteErrorMessage'), array(UPLOAD_ERR_EXTENSION, 'uploadExtensionErrorMessage'));
     if (class_exists('Symfony\\Component\\HttpFoundation\\File\\UploadedFile')) {
         $tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array('{{ limit }}' => UploadedFile::getMaxFilesize() . ' bytes'));
     }
     return $tests;
 }
开发者ID:nashadalam,项目名称:symfony,代码行数:8,代码来源:FileValidatorTest.php

示例12: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof File) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\File');
     }
     if (null === $value || '' === $value) {
         return;
     }
     if ($value instanceof UploadedFile && !$value->isValid()) {
         switch ($value->getError()) {
             case UPLOAD_ERR_INI_SIZE:
                 if ($constraint->maxSize) {
                     if (ctype_digit((string) $constraint->maxSize)) {
                         $limitInBytes = (int) $constraint->maxSize;
                     } elseif (preg_match('/^\\d++k$/', $constraint->maxSize)) {
                         $limitInBytes = $constraint->maxSize * self::KB_BYTES;
                     } elseif (preg_match('/^\\d++M$/', $constraint->maxSize)) {
                         $limitInBytes = $constraint->maxSize * self::MB_BYTES;
                     } else {
                         throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $constraint->maxSize));
                     }
                     $limitInBytes = min(UploadedFile::getMaxFilesize(), $limitInBytes);
                 } else {
                     $limitInBytes = UploadedFile::getMaxFilesize();
                 }
                 $this->context->addViolation($constraint->uploadIniSizeErrorMessage, array('{{ limit }}' => $limitInBytes, '{{ suffix }}' => 'bytes'));
                 return;
             case UPLOAD_ERR_FORM_SIZE:
                 $this->context->addViolation($constraint->uploadFormSizeErrorMessage);
                 return;
             case UPLOAD_ERR_PARTIAL:
                 $this->context->addViolation($constraint->uploadPartialErrorMessage);
                 return;
             case UPLOAD_ERR_NO_FILE:
                 $this->context->addViolation($constraint->uploadNoFileErrorMessage);
                 return;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $this->context->addViolation($constraint->uploadNoTmpDirErrorMessage);
                 return;
             case UPLOAD_ERR_CANT_WRITE:
                 $this->context->addViolation($constraint->uploadCantWriteErrorMessage);
                 return;
             case UPLOAD_ERR_EXTENSION:
                 $this->context->addViolation($constraint->uploadExtensionErrorMessage);
                 return;
             default:
                 $this->context->addViolation($constraint->uploadErrorMessage);
                 return;
         }
     }
     if (!is_scalar($value) && !$value instanceof FileObject && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
     if (!is_file($path)) {
         $this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path));
         return;
     }
     if (!is_readable($path)) {
         $this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path));
         return;
     }
     if ($constraint->maxSize) {
         $sizeInBytes = filesize($path);
         $limitInBytes = (int) $constraint->maxSize;
         if (preg_match('/^\\d++k$/', $constraint->maxSize)) {
             $limitInBytes *= self::KB_BYTES;
         } elseif (preg_match('/^\\d++M$/', $constraint->maxSize)) {
             $limitInBytes *= self::MB_BYTES;
         } elseif (!ctype_digit((string) $constraint->maxSize)) {
             throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $constraint->maxSize));
         }
         if ($sizeInBytes > $limitInBytes) {
             // Convert the limit to the smallest possible number
             // (i.e. try "MB", then "kB", then "bytes")
             $coef = self::MB_BYTES;
             $limitAsString = (string) ($limitInBytes / $coef);
             // Restrict the limit to 2 decimals (without rounding! we
             // need the precise value)
             while (self::moreDecimalsThan($limitAsString, 2)) {
                 $coef /= 1000;
                 $limitAsString = (string) ($limitInBytes / $coef);
             }
             // Convert size to the same measure, but round to 2 decimals
             $sizeAsString = (string) round($sizeInBytes / $coef, 2);
             // If the size and limit produce the same string output
             // (due to rounding), reduce the coefficient
             while ($sizeAsString === $limitAsString) {
                 $coef /= 1000;
                 $limitAsString = (string) ($limitInBytes / $coef);
                 $sizeAsString = (string) round($sizeInBytes / $coef, 2);
             }
             $this->context->addViolation($constraint->maxSizeMessage, array('{{ size }}' => $sizeAsString, '{{ limit }}' => $limitAsString, '{{ suffix }}' => static::$suffices[$coef], '{{ file }}' => $path));
             return;
         }
     }
     if ($constraint->mimeTypes) {
//.........这里部分代码省略.........
开发者ID:hafedhbou,项目名称:hetic-p2017,代码行数:101,代码来源:FileValidator.php

示例13: formAction


//.........这里部分代码省略.........
  */
 public function formAction($id, Request $request)
 {
     $productAdapter = $this->container->get('prestashop.adapter.data_provider.product');
     $product = $productAdapter->getProduct($id);
     if (!$product || empty($product->id)) {
         return $this->redirectToRoute('admin_product_catalog');
     }
     $shopContext = $this->get('prestashop.adapter.shop.context');
     $legacyContextService = $this->get('prestashop.adapter.legacy.context');
     $legacyContext = $legacyContextService->getContext();
     $isMultiShopContext = count($shopContext->getContextListShopID()) > 1 ? true : false;
     // Redirect to legacy controller (FIXME: temporary behavior)
     $pagePreference = $this->container->get('prestashop.core.admin.page_preference_interface');
     /* @var $pagePreference AdminPagePreferenceInterface */
     if ($pagePreference->getTemporaryShouldUseLegacyPage('product')) {
         $legacyUrlGenerator = $this->container->get('prestashop.core.admin.url_generator_legacy');
         /* @var $legacyUrlGenerator UrlGeneratorInterface */
         return $this->redirect($legacyUrlGenerator->generate('admin_product_form', array('id' => $id)), 302);
     }
     $response = new JsonResponse();
     $modelMapper = new ProductAdminModelAdapter($product, $this->container->get('prestashop.adapter.legacy.context'), $this->container->get('prestashop.adapter.admin.wrapper.product'), $this->container->get('prestashop.adapter.tools'), $productAdapter, $this->container->get('prestashop.adapter.data_provider.supplier'), $this->container->get('prestashop.adapter.data_provider.warehouse'), $this->container->get('prestashop.adapter.data_provider.feature'), $this->container->get('prestashop.adapter.data_provider.pack'), $this->container->get('prestashop.adapter.shop.context'));
     $adminProductWrapper = $this->container->get('prestashop.adapter.admin.wrapper.product');
     $form = $this->createFormBuilder($modelMapper->getFormData())->add('id_product', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\HiddenType')->add('step1', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductInformation')->add('step2', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductPrice')->add('step3', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductQuantity')->add('step4', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductShipping')->add('step5', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductSeo')->add('step6', 'PrestaShopBundle\\Form\\Admin\\Product\\ProductOptions')->getForm();
     $formBulkCombinations = $this->createForm('PrestaShopBundle\\Form\\Admin\\Product\\ProductCombinationBulk', null, array('iso_code' => $this->get('prestashop.adapter.legacy.context')->getContext()->currency->iso_code, 'price_display_precision' => $this->configuration->get('_PS_PRICE_DISPLAY_PRECISION_')));
     $form->handleRequest($request);
     $formData = $form->getData();
     if ($form->isSubmitted()) {
         if ($form->isValid()) {
             // Legacy code. To fix when Object model will change. But report Hooks.
             $postData = $request->request->all();
             $combinations = array();
             foreach ((array) $postData as $postKey => $postValue) {
                 if (preg_match('/^combination_.*/', $postKey)) {
                     $combinations[$postKey] = $postValue;
                 }
             }
             $formData['step3']['combinations'] = $combinations;
             //define POST values for keeping legacy adminController skills
             $_POST = $modelMapper->getModelData($formData, $isMultiShopContext) + $_POST;
             $_POST['state'] = \Product::STATE_SAVED;
             $adminProductController = $adminProductWrapper->getInstance();
             $adminProductController->setIdObject($formData['id_product']);
             $adminProductController->setAction('save');
             // Hooks: this will trigger legacy AdminProductController, postProcess():
             // actionAdminSaveBefore; actionAdminProductsControllerSaveBefore
             // actionProductAdd or actionProductUpdate (from processSave() -> processAdd() or processUpdate())
             // actionAdminSaveAfter; actionAdminProductsControllerSaveAfter
             if ($product = $adminProductController->postCoreProcess()) {
                 $adminProductController->processSuppliers($product->id);
                 $adminProductController->processFeatures($product->id);
                 $adminProductController->processSpecificPricePriorities();
                 foreach ($_POST['combinations'] as $combinationValues) {
                     $adminProductWrapper->processProductAttribute($product, $combinationValues);
                     // For now, each attribute set the same value.
                     $adminProductWrapper->processDependsOnStock($product, $_POST['depends_on_stock'] == '1', $combinationValues['id_product_attribute']);
                 }
                 $adminProductWrapper->processDependsOnStock($product, $_POST['depends_on_stock'] == '1');
                 // If there is no combination, then quantity is managed for the whole product (as combination ID 0)
                 // In all cases, legacy hooks are triggered: actionProductUpdate and actionUpdateQuantity
                 if (count($_POST['combinations']) === 0) {
                     $adminProductWrapper->processQuantityUpdate($product, $_POST['qty_0']);
                 }
                 // else quantities are managed from $adminProductWrapper->processProductAttribute() above.
                 $adminProductWrapper->processProductOutOfStock($product, $_POST['out_of_stock']);
                 $adminProductWrapper->processProductCustomization($product, $_POST['custom_fields']);
                 $adminProductWrapper->processAttachments($product, $_POST['attachments']);
                 $adminProductController->processWarehouses();
                 $response->setData(['product' => $product]);
             }
             if ($request->isXmlHttpRequest()) {
                 return $response;
             }
         } elseif ($request->isXmlHttpRequest()) {
             $response->setStatusCode(400);
             $response->setData($this->getFormErrorsForJS($form));
             return $response;
         }
     }
     $stockManager = $this->container->get('prestashop.core.data_provider.stock_interface');
     /* @var $stockManager StockInterface */
     $warehouseProvider = $this->container->get('prestashop.adapter.data_provider.warehouse');
     /* @var $warehouseProvider WarehouseDataProvider */
     //If context shop is define to a group shop, disable the form
     if ($legacyContext->shop->getContext() == $shopContext->getShopContextGroupConstant()) {
         return $this->render('PrestaShopBundle:Admin/Product:formDisable.html.twig', ['showContentHeader' => false]);
     }
     // languages for switch dropdown
     $languages = $legacyContextService->getLanguages();
     // generate url preview
     if ($product->active) {
         $preview_url = $adminProductWrapper->getPreviewUrl($product);
         $preview_url_deactive = $adminProductWrapper->getPreviewUrlDeactivate($preview_url);
     } else {
         $preview_url_deactive = $adminProductWrapper->getPreviewUrl($product, false);
         $preview_url = $adminProductWrapper->getPreviewUrlDeactivate($preview_url_deactive);
     }
     $attributeGroups = $this->getDoctrine()->getManager()->getRepository('PrestaShopBundle:Attribute')->findByLangAndShop(1, 1);
     return array('form' => $form->createView(), 'formCombinations' => $formBulkCombinations->createView(), 'categories' => $this->get('prestashop.adapter.data_provider.category')->getCategoriesWithBreadCrumb(), 'id_product' => $id, 'ids_product_attribute' => isset($formData['step3']['id_product_attributes']) ? implode(',', $formData['step3']['id_product_attributes']) : '', 'has_combinations' => isset($formData['step3']['id_product_attributes']) && count($formData['step3']['id_product_attributes']) > 0, 'combinations_count' => isset($formData['step3']['id_product_attributes']) ? count($formData['step3']['id_product_attributes']) : 0, 'asm_globally_activated' => $stockManager->isAsmGloballyActivated(), 'warehouses' => $stockManager->isAsmGloballyActivated() ? $warehouseProvider->getWarehouses() : [], 'is_multishop_context' => $isMultiShopContext, 'is_combination_active' => $this->get('prestashop.adapter.legacy.configuration')->combinationIsActive(), 'showContentHeader' => false, 'preview_link' => $preview_url, 'preview_link_deactivate' => $preview_url_deactive, 'stats_link' => $legacyContextService->getAdminLink('AdminStats', true, ['module' => 'statsproduct', 'id_product' => $id]), 'help_link' => $this->generateSidebarLink('AdminProducts'), 'languages' => $languages, 'default_language_iso' => $languages[0]['iso_code'], 'attribute_groups' => $attributeGroups, 'max_upload_size' => \Tools::formatBytes(UploadedFile::getMaxFilesize()));
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:101,代码来源:ProductController.php

示例14:

 /** @test */
 function it_gets_and_sets_max_upload_size()
 {
     $this->assertEquals($this->uploadService->maxUploadSize(), UploadedFile::getMaxFilesize());
     $this->assertEquals($this->uploadService->validatesUploadedFile(50000), 50000);
     $this->assertEquals($this->uploadService->validatesUploadedFile(), 50000);
 }
开发者ID:kenarkose,项目名称:transit,代码行数:7,代码来源:UploadServiceTest.php

示例15: getUploadMaxFileSize

 /**
  * Get POST max file size
  *
  * @return integer
  */
 private function getUploadMaxFileSize()
 {
     $postMaxSize = trim(ini_get('post_max_size'));
     if ('' === $postMaxSize) {
         $postMaxSize = PHP_INT_MAX;
     }
     switch (strtolower(substr($postMaxSize, -1))) {
         case 'g':
             $postMaxSize *= 1024;
         case 'm':
             $postMaxSize *= 1024;
         case 'k':
             $postMaxSize *= 1024;
     }
     return min(UploadedFile::getMaxFilesize(), (int) $postMaxSize);
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:21,代码来源:Upload.php


注:本文中的Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。