WarpConduit Computing

  • Quick Tips
  • Web Design & Development
  • Graphic Design
  • Home
  • WordPress Plugins
  • Password Generator
  • About
  • Contact

Increase Image Upload File Size Limit on OpenCart 1.4.9.3

February 4, 2011 by Josh Hartman

OpenCart’s default image upload size is 300KB and that is simply too small for clients that don’t have the knowledge to resize their images before uploading them. Although uploading digital camera images does use more bandwidth, sometimes it can not be avoided. To adjust the image upload size make the following changes around line 446 of admin/controller/common/filemanager.php:

if ($this->request->files['image']['size'] > 10485760) {
	$json['error'] = $this->language->get('error_file_size');
}

if ($this->request->files['image']['size'] > 10485760) { $json['error'] = $this->language->get('error_file_size'); }

In this case we have increased the upload size limit to 10MB, also make sure that your php configuration will allow file uploads and posts of this size.

Now you have these big images uploaded, but sometimes GD can run out of memory trying to resize these large images. You can solve this by using imagemagick, if available. So what we’re going to do is resize all images larger than 1000×1000 down to 1000×1000. Make the following changes around line 490 of admin/controller/common/filemanager.php:

if (!isset($json['error'])) {	
	if(substr($this->request->files['image']['type'],0,5)=='image'){
		$imageinfo = getimagesize($this->request->files['image']['tmp_name']);
		if($imageinfo[0]>1000 || $imageinfo[1]>1000){
			exec('convert -colorspace RGB "'.$this->request->files['image']['tmp_name'].'" -resize 1000x1000 "'.$this->request->files['image']['tmp_name'].'"');
		}
	}
	if (@move_uploaded_file($this->request->files['image']['tmp_name'], $directory . '/' . basename($this->request->files['image']['name']))) {		
		$json['success'] = $this->language->get('text_uploaded');
	} else {
		$json['error'] = $this->language->get('error_uploaded');
	}
}

if (!isset($json['error'])) { if(substr($this->request->files['image']['type'],0,5)=='image'){ $imageinfo = getimagesize($this->request->files['image']['tmp_name']); if($imageinfo[0]>1000 || $imageinfo[1]>1000){ exec('convert -colorspace RGB "'.$this->request->files['image']['tmp_name'].'" -resize 1000x1000 "'.$this->request->files['image']['tmp_name'].'"'); } } if (@move_uploaded_file($this->request->files['image']['tmp_name'], $directory . '/' . basename($this->request->files['image']['name']))) { $json['success'] = $this->language->get('text_uploaded'); } else { $json['error'] = $this->language->get('error_uploaded'); } }

That’s it, your image upload file size limit has been lifted and memory usage issues have been dealt with!

Filed Under: Web Design & Development Tagged With: image, limit, opencart, php, size, upload

Comments

  1. Doug says

    January 1, 2012 at 2:42 AM

    Is there a way that will not cause problems upgrading?

    • Josh Hartman says

      January 3, 2012 at 12:03 PM

      You may want to look at vQmod (http://code.google.com/p/vqmod/) for that purpose, it was created originally for OpenCart updates like this.

  2. Andrian Minchev says

    February 9, 2012 at 7:42 AM

    Thank you very much! This article is very helpfull for hardcoded change to opencart.

    • CharlesV says

      March 10, 2012 at 11:25 AM

      Here there is an extension that increases the size and the resolution.

      http://www.opencart.com/index.php?route=extension/extension/info&extension_id=3863

      • Josh Hartman says

        March 10, 2012 at 6:28 PM

        Thanks Charles. Though a premium extension, it could be a good option for those who are not comfortable using vQmod or modifying code.

  3. paulmarr says

    February 8, 2013 at 11:25 AM

    thanks .great help.

  4. Indian Saree says

    August 17, 2013 at 12:03 AM

    Thanks for this valuable information..

Connect

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • Extremely Useful Applications for Web Development and IT Tasks
  • Installing BookStack Wiki on cPanel Shared Hosting
  • Media (MIME) Type Reference List

Tags

automatic base64 benchmark cache counter css deflate email font gzip htaccess html image inarray increment inline images in_array javascript jquery link list magento mailto menu metadot mysql number obfuscation opencart operating system order php random redirect rewriterule slashes software timestamp ubuntu unix upgrade url windows windows 7 wordpress

Blogroll

  • CodeIgniter
  • Fusion Forward
  • jQuery
  • Nettuts+
  • Smashing Magazine

© 2021 WarpConduit Computing. All Rights Reserved.