{"id":177096,"date":"2019-05-29T13:02:43","date_gmt":"2019-05-29T13:02:43","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=177096"},"modified":"2022-04-04T11:59:00","modified_gmt":"2022-04-04T11:59:00","slug":"validate-post-image-size-exceeding-post_max_size-in-prestashop","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/","title":{"rendered":"Validate post image size exceeding &#8216;post_max_size&#8217; in PrestaShop"},"content":{"rendered":"<p>On the server, a setting <a href=\"https:\/\/www.php.net\/manual\/en\/ini.core.php#ini.post-max-size\">&#8220;post_max_size&#8221;<\/a> defines the length\/size of the data in a single request to the server. When the form data is greater than this value, the server discards whole data and you cannot apply proper validation.<\/p>\n<p>For example, If the value of &#8220;post_max_size&#8221; is &#8220;8M&#8221; in php.ini, and you try to upload an image of size 9 MB, then this issue will occur and you will not get any data in $_POST or $_FILES.<\/p>\n<p>In this case, you cannot validate any of the data at the server end as the server discards whole form data.<\/p>\n<p>To avoid this issue, you have to consider a data size limit by which you will validate the data in javascript before form submission. This limit should be equivalent to &#8220;post_max_size&#8221;.<\/p>\n<p>In PrestaShop, you can find the setting for this limit. Go to Administration-Maximum size for attached files. PrestaShop saves this limit value in &#8216;PS_ATTACHMENT_MAXIMUM_SIZE&#8217; configuration.<\/p>\n<p>You can check the size of the image as soon as you select the image to upload. If this size exceeds the limit, we can show alert and reset the file input.<\/p>\n<p>First, assign two variables for javascript in your controller:<\/p>\n<pre class=\"brush:php\">Media::addJsDef(\n    array(\n        'filesizeError' =&gt; $this-&gt;l('File exceeds maximum size.'),\n        'maxSizeAllowed' =&gt; Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE'),\n    )\n);<\/pre>\n<p class=\"brush:php\">Your javascript file will use these variables. It will use &#8220;maxSizeAllowed&#8221; to compare size and &#8220;filesizeError&#8221; to show error message. Now in your javascript file, write this code:<\/p>\n<pre class=\"brush:js\">$('input[type=\"file\"]').on('change', function() {\n    if (typeof this.files[0] != 'undefined') {\n        if (this.files[0].size &gt; maxSizeAllowed*1000000) {\n            alert(filesizeError);\n            this.value = \"\";\n        }\n    }\n});<\/pre>\n<p class=\"brush:js\">Now, each time you try to upload an image having a size greater than PS_ATTACHMENT_MAXIMUM_SIZE, the page will show an alert and file input will reset.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On the server, a setting &#8220;post_max_size&#8221; defines the length\/size of the data in a single request to the server. When the form data is greater than this value, the server discards whole data and you cannot apply proper validation. For example, If the value of &#8220;post_max_size&#8221; is &#8220;8M&#8221; in php.ini, and you try to upload <a href=\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":264,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,13,209],"tags":[8817,8816,8815,2065,131],"class_list":["post-177096","post","type-post","status-publish","format-standard","hentry","category-jquery","category-php","category-prestashop","tag-exceed","tag-image-size","tag-post_max_size","tag-prestashop","tag-validation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PrestaShop: Validate form data if uploaded image exceeds post_max_size<\/title>\n<meta name=\"description\" content=\"When posted image size exceeds post_max_size, the form data is discarded in PrestaShop. Validate this in JavaScript to ensure server does not discard data.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PrestaShop: Validate form data if uploaded image exceeds post_max_size\" \/>\n<meta property=\"og:description\" content=\"When posted image size exceeds post_max_size, the form data is discarded in PrestaShop. Validate this in JavaScript to ensure server does not discard data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-29T13:02:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-04T11:59:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ram Chandra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ram Chandra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\"},\"author\":{\"name\":\"Ram Chandra\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/abcd2edf640c51cd905386b99118ad71\"},\"headline\":\"Validate post image size exceeding &#8216;post_max_size&#8217; in PrestaShop\",\"datePublished\":\"2019-05-29T13:02:43+00:00\",\"dateModified\":\"2022-04-04T11:59:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\"},\"wordCount\":272,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"exceed\",\"image size\",\"post_max_size\",\"prestashop\",\"validation\"],\"articleSection\":[\"jQuery\",\"php\",\"prestashop\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\",\"url\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\",\"name\":\"PrestaShop: Validate form data if uploaded image exceeds post_max_size\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2019-05-29T13:02:43+00:00\",\"dateModified\":\"2022-04-04T11:59:00+00:00\",\"description\":\"When posted image size exceeds post_max_size, the form data is discarded in PrestaShop. Validate this in JavaScript to ensure server does not discard data.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Validate post image size exceeding &#8216;post_max_size&#8217; in PrestaShop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/abcd2edf640c51cd905386b99118ad71\",\"name\":\"Ram Chandra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a237e2b96f2a8989c930db6c377971a3d52601b0bba3c5e3dc79a88205178d26?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a237e2b96f2a8989c930db6c377971a3d52601b0bba3c5e3dc79a88205178d26?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ram Chandra\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/ram-chandra178\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PrestaShop: Validate form data if uploaded image exceeds post_max_size","description":"When posted image size exceeds post_max_size, the form data is discarded in PrestaShop. Validate this in JavaScript to ensure server does not discard data.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/","og_locale":"en_US","og_type":"article","og_title":"PrestaShop: Validate form data if uploaded image exceeds post_max_size","og_description":"When posted image size exceeds post_max_size, the form data is discarded in PrestaShop. Validate this in JavaScript to ensure server does not discard data.","og_url":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2019-05-29T13:02:43+00:00","article_modified_time":"2022-04-04T11:59:00+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Ram Chandra","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ram Chandra","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/"},"author":{"name":"Ram Chandra","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/abcd2edf640c51cd905386b99118ad71"},"headline":"Validate post image size exceeding &#8216;post_max_size&#8217; in PrestaShop","datePublished":"2019-05-29T13:02:43+00:00","dateModified":"2022-04-04T11:59:00+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/"},"wordCount":272,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["exceed","image size","post_max_size","prestashop","validation"],"articleSection":["jQuery","php","prestashop"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/","url":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/","name":"PrestaShop: Validate form data if uploaded image exceeds post_max_size","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2019-05-29T13:02:43+00:00","dateModified":"2022-04-04T11:59:00+00:00","description":"When posted image size exceeds post_max_size, the form data is discarded in PrestaShop. Validate this in JavaScript to ensure server does not discard data.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/validate-post-image-size-exceeding-post_max_size-in-prestashop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Validate post image size exceeding &#8216;post_max_size&#8217; in PrestaShop"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/abcd2edf640c51cd905386b99118ad71","name":"Ram Chandra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a237e2b96f2a8989c930db6c377971a3d52601b0bba3c5e3dc79a88205178d26?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a237e2b96f2a8989c930db6c377971a3d52601b0bba3c5e3dc79a88205178d26?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ram Chandra"},"url":"https:\/\/webkul.com\/blog\/author\/ram-chandra178\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/177096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/264"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=177096"}],"version-history":[{"count":9,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/177096\/revisions"}],"predecessor-version":[{"id":327579,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/177096\/revisions\/327579"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=177096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=177096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=177096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}