Jump to content

Cookie usage in module


ceadreak

Recommended Posts

Hello all,

 

I am currently make a module for a client and I have a strange bug ...

The module is simply a flash progress bar for replace the simple "browse file type" into the product.tpl (into the product customization) but I can't recover my $_FILES values in the ProductController.php.

 

I try to pass the $_FILES array in the $cookie global var.

 

With a debug into the ProductController, function PictureUpload(), I can see my cookie values but not the $_FILES value !

 

In my code down, you can see I try to get a test value in the PictureUpload() function and display it in a debug array.

 

Please watch my test here and tell me what's wrong ...

 

 

Thanks in advance

 

Ps : I use the swfupload.swf script to display my progressbar ( http://code.google.c.../downloads/list)

 

Here is my template :

 

<div class="customizationUploadBrowse">
			<input type="file" name="flash_file{$field.id_customization_field}" id="flash_img{$customizationField}" class="customization_block_input {if isset($pictures.$key)}filled{/if}" />{if $field.re
			<script>
			  $(function() {
				$("#flash_img{$customizationField}").makeAsyncUploader({
				  upload_url: "{$modules_dir}flashprogressbar/upload.php", // Important! This isn't a directory, it's a HANDLER such as an ASP.NET MVC action method, or a PHP file, or a Classic ASP file,
				  flash_url: '{$modules_dir}flashprogressbar/swfupload.swf',
				  button_image_url: '{$modules_dir}flashprogressbar/blankButton.png',
				  button_text: 'Parcourir',
				  //file_size_limit: '50 MB',
				  //debug: true
				  //disableDuringUpload: INPUT[type='submit'],
				});
			  });
			</script>
		  <div class="customizationUploadBrowseDescription">{if !empty($field.name)}{$field.name}{else}{l s='Please select an image file from your hard drive'}{/if}</div></div>

 

You can see in the swfupload config, I call a script "upload.php"

 

Upload.php contains :

 

<?php
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/flashprogressbar.php');[/font]
include(dirname(__FILE__).'/../../init.php');[/font]

global $cookie;
$cookie->test = 'test';
?>

 

And the productController.php overload with my debug :

 

<?php
class ProductController extends ProductControllerCore {

 public function displayContent()
 {
//parent::displayContent();
$version = str_replace('.', '', _PS_VERSION_);
self::$smarty->display(_PS_MODULE_DIR_.'flashprogressbar/product_' . $version . '.tpl');
 }

 public function pictureUpload(Product $product, Cart $cart)
 {
global $cookie;
echo '<pre>';
print_r($cookie);
echo '</pre>';
if (!$fieldIds = $this->product->getCustomizationFieldIds())
  return false;
$authorizedFileFields = array();
foreach ($fieldIds AS $fieldId)
  if ($fieldId['type'] == _CUSTOMIZE_FILE_)
	$authorizedFileFields[(int)($fieldId['id_customization_field'])] = 'file'.(int)($fieldId['id_customization_field']);
$indexes = array_flip($authorizedFileFields);
foreach ($_FILES AS $fieldName => $file)
  if (in_array($fieldName, $authorizedFileFields) AND isset($file['tmp_name']) AND !empty($file['tmp_name']))
  {
	$fileName = md5(uniqid(rand(), true));
	if ($error = checkImage($file, (int)(Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))))
	  $this->errors[] = $error;

	if ($error OR (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($file['tmp_name'], $tmpName)))
	  return false;
	/* Original file */
	elseif (!imageResize($tmpName, _PS_UPLOAD_DIR_.$fileName))
	  $this->errors[] = Tools::displayError('An error occurred during the image upload.');
	/* A smaller one */
	elseif (!imageResize($tmpName, _PS_UPLOAD_DIR_.$fileName.'_small', (int)(Configuration::get('PS_PRODUCT_PICTURE_WIDTH')), (int)(Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'))))
	  $this->errors[] = Tools::displayError('An error occurred during the image upload.');
	elseif (!chmod(_PS_UPLOAD_DIR_.$fileName, 0777) OR !chmod(_PS_UPLOAD_DIR_.$fileName.'_small', 0777))
	  $this->errors[] = Tools::displayError('An error occurred during the image upload.');
	else
	  $cart->addPictureToProduct((int)($this->product->id), $indexes[$fieldName], $fileName);
	unlink($tmpName);
  }
return true;
 }

}

 

 

The debug :

 

 


Cookie Object
(
[_content:protected] => Array
	(
		[date_add] => 2012-04-25 13:53:33
		[id_lang] => 2
		[id_currency] => 1
		[viewed] => 7
		[id_guest] => 3
		[id_connections] => 4
		[last_visited_category] => 2
		[id_cart] => 2
	)

[_name:protected] => 8812c36aa5ae336c2a77bf63211d899a
[_expire:protected] => 1337095970
[_domain:protected] =>
[_path:protected] => /prestashop/
[_cipherTool:protected] => Rijndael Object
	(
		[_key:protected] => EZ6W8Bw3sI5dMzgwGKeUEU71RyQrhMRt
		[_iv:protected] => �ɤˬ���r�J'��+
	)

[_key:protected] => yRL0YB7txN5w7e4KX7kMSU8qV3LriB4oopuwCSSYXKuSQmEv2Exqfvoa
[_iv:protected] => QCvLAysb
[_modified:protected] =>
)

 

 

 

Please help me ...

 

 

 

Best regards

Link to comment
Share on other sites

Maybe that's because I call the upload.php script from flash animation "swfupload.swf" ??

 

When I call upload.php script manually from my browser, it works perfectly ...

 

I don't understand ...

 

 

Thanks for your help !

Link to comment
Share on other sites

Hi CartExpert.net and thank you for your interrest to my post.

 

I use flash to select files and display the progressbar.

 

That's not for a dedicated server, else I could have used php-apc extension ...

 

Here I can't use php-apc or php-uplaodprogress.

 

 

Thanks for your help !

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...