Jump to content

File upload attached to a product only accept (.gif .jpg. png) How to change this ?


Recommended Posts

Hi.

 

The topic title says it all.

 

How do I change the allowed file types being uploaded by the customer, when the customer are moving a product to the cart when the product is set to require a file being attached by the customer ??

Link to comment
Share on other sites

You need to change the following setting in order to achieve same.

In ProductController.php aroung 632 line, you will find following line of code that you have to put into commented out.

 

 

if ($error = ImageManager::validateUpload($file, (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE')))
$this->errors[] = $error;
 
Please do back up for any changes you want to made.
 
Thanks
Link to comment
Share on other sites

I am a complete noob to cooding. So what do I have to change exactly? I want to change the allowed file type to (.tiff, .tif, .psd) and allow 600MB file size upload.

 

So what do I have to change in this code.:

protected function pictureUpload()
	{
		if (!$field_ids = $this->product->getCustomizationFieldIds())
			return false;
		$authorized_file_fields = array();
		foreach ($field_ids as $field_id)
			if ($field_id['type'] == Product::CUSTOMIZE_FILE)
				$authorized_file_fields[(int)$field_id['id_customization_field']] = 'file'.(int)$field_id['id_customization_field'];
		$indexes = array_flip($authorized_file_fields);
		foreach ($_FILES as $field_name => $file)
			if (in_array($field_name, $authorized_file_fields) && isset($file['tmp_name']) && !empty($file['tmp_name']))
			{
				$file_name = md5(uniqid(rand(), true));
				if ($error = ImageManager::validateUpload($file, (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE')))
					$this->errors[] = $error;

				$product_picture_width = (int)Configuration::get('PS_PRODUCT_PICTURE_WIDTH');
				$product_picture_height = (int)Configuration::get('PS_PRODUCT_PICTURE_HEIGHT');
				$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
				if ($error || (!$tmp_name || !move_uploaded_file($file['tmp_name'], $tmp_name)))
					return false;
				/* Original file */
				if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name))
					$this->errors[] = Tools::displayError('An error occurred during the image upload process.');
				/* A smaller one */
				elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name.'_small', $product_picture_width, $product_picture_height))
					$this->errors[] = Tools::displayError('An error occurred during the image upload process.');
				elseif (!chmod(_PS_UPLOAD_DIR_.$file_name, 0777) || !chmod(_PS_UPLOAD_DIR_.$file_name.'_small', 0777))
					$this->errors[] = Tools::displayError('An error occurred during the image upload process.');
				else
					$this->context->cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name);
				unlink($tmp_name);
			}
		return true;
	}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...