Jump to content

Problem uploading image after 1.5.4


Recommended Posts

Greetings,

 

I get this error during uploading a image in a template module.

It's the only error I get after updating to 1.5.4

I tried a bunch of things but I'm a bit dazzled, can anyone see what is wrong here ?

 

Thanks in advance!

 

This is the error I get on a blank browser page:

 

[PrestaShop] Fatal error in module tmpics:
Call to undefined function checkImage()

 

This is my checkimage code ...

 

/* upload the image */
if (isset($_FILES['link_'.$i.'_img']) AND isset($_FILES['link_'.$i.'_img']['tmp_name']) AND !empty($_FILES['link_'.$i.'_img']['tmp_name']))
{
 Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);
 if ($error = checkImage($_FILES['link_'.$i.'_img'], $this->maxImageSize))
  $this->_html .= $error;
elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['link_'.$i.'_img']['tmp_name'], $tmpName))
 return false;
			elseif (!imageResize($tmpName, dirname(__FILE__).'/slides/slide_0'.$i.'.jpg'))
 $this->_html .= $this->displayError($this->l('An error occurred during the image upload.'));
			unlink($tmpName);
}
if ($line = $this->putContent($newXml, 'img', 'slides/slide_0'.$i.'.jpg'))
 $newXml .= $line;
$newXml .= "\n".' </link>'."\n";
$i++;
  }
  $newXml .= '</links>'."\n";

Link to comment
Share on other sites

Hi,

 

Could you paste here the function including the declaration such as below, and the context?

A quick hint: If you are using a local where the letter I hasn't its lower case as i, such as in icelandic or turkish, you might experience this kind of problems.

function checkImage()
{
//your good stuff
}

Link to comment
Share on other sites

Hi,

 

Could you paste here the function including the declaration such as below, and the context?

A quick hint: If you are using a local where the letter I hasn't its lower case as i, such as in icelandic or turkish, you might experience this kind of problems.

function checkImage()
{
//your good stuff
}

 

Hey thanks for your time and hints ;) but that function directly I cannot find...

I'll past you the full code !

 

<?php

 function getContent()
 {
	global $cookie;
	/* Languages preliminaries */
	$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
	$languages = Language::getLanguages();
	$iso = Language::getIsoById($defaultLanguage);
	$isoUser = Language::getIsoById(intval($cookie->id_lang));

/* display the module name */
$this->_html = '<h2>'.$this->displayName.' '.$this->version.'</h2>';
/* update the editorial xml */
if (isset($_POST['submitUpdate']))
{
  // Generate new XML data
  $newXml = '<?xml version=\'1.0\' encoding=\'utf-8\' ?>'."\n";
  $newXml .= '<links>'."\n";
  $i = 0;
  foreach ($_POST['link'] as $link)
  {
$newXml .= ' <link>';
foreach ($link AS $key => $field)
{
 if ($line = $this->putContent($newXml, $key, $field))
  $newXml .= $line;
}
/* upload the image */
if (isset($_FILES['link_'.$i.'_img']) AND isset($_FILES['link_'.$i.'_img']['tmp_name']) AND !empty($_FILES['link_'.$i.'_img']['tmp_name']))
{
 Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);
 if ($error = checkImage($_FILES['link_'.$i.'_img'], $this->maxImageSize))
  $this->_html .= $error;
elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['link_'.$i.'_img']['tmp_name'], $tmpName))
 return false;
			elseif (!imageResize($tmpName, dirname(__FILE__).'/slides/slide_0'.$i.'.jpg'))
 $this->_html .= $this->displayError($this->l('An error occurred during the image upload.'));
			unlink($tmpName);
}
if ($line = $this->putContent($newXml, 'img', 'slides/slide_0'.$i.'.jpg'))
 $newXml .= $line;
$newXml .= "\n".' </link>'."\n";
$i++;
  }
  $newXml .= '</links>'."\n";
  /* write it into the editorial xml file */
  if ($fd = @fopen(dirname(__FILE__).'/links.xml', 'w'))
  {
if (!@fwrite($fd, $newXml))
 $this->_html .= $this->displayError($this->l('Unable to write to the editor file.'));
if (!@fclose($fd))
 $this->_html .= $this->displayError($this->l('Can\'t close the editor file.'));
  }
  else
$this->_html .= $this->displayError($this->l('Unable to update the editor file.<br />Please check the editor file\'s writing permissions.'));
}
 if (Tools::isSubmit('submitUpdate'))
 {
$output = '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
 }
  /* display the editorial's form */
$this->_displayForm();
return $this->_html;
 }
static private function getXmlFilename()
{
 return 'links.xml';
}
private function _getXml()
{
 if (file_exists(dirname(__FILE__).'/'.$this->getXmlFilename()))
 {
  if ($xml = @simplexml_load_file(dirname(__FILE__).'/'.$this->getXmlFilename()))
return $xml;
 }
 return false;
}
public function _getFormItem($i, $last)
{
 global $cookie;
 $this->_xml = $this->_getXml();
 $isoUser = Language::getIsoById(intval($cookie->id_lang));
 $divLangName = 'texts'.$i;
 $output = '
  <div class="item" id="item'.$i.'" style="position:relative;">
<h3>'.$this->l('Item #').($i+1).'</h3>
<input type="hidden" name="item_'.$i.'_item" value="" />';
 $output .= '
<label>'.$this->l('Slide image').'</label>
<div class="margin-form">
 <div><img src="'.$this->_path.'slides/slide_0'.$i.'.jpg" alt="" title="" style="width:250px; height:auto;" /></div>
 <input type="file" name="link_'.$i.'_img" />
 <p style="clear: both"></p>
</div>';
 $output .= '
<label>'.$this->l('Slide URL').'</label>
<div class="margin-form" style="padding-left:0">
 <input type="text" name="link['.$i.'][url]" size="64" value="'.$this->_xml->link[$i]->url.'" />
 <p style="clear: both"></p>
</div>';

 $output .= '<fieldset style="font-size:1em;">';
 $output .= '<div style="position:absolute;">';
 $output .= $this->displayFlags($this->_languages, $this->_defaultLanguage, $divLangName , 'texts'.$i, true);
 $output .= '</div>';

 foreach ($this->_languages as $language)
 {

 $output .= '<div id="texts'.$i.'_'.$language['id_lang'].'" style="display:'.($language['id_lang'] == $this->_defaultLanguage ? 'block' : 'none').';">';

 $output .= '
<label>'.$this->l('Field #1').'</label>
<div class="margin-form" style="padding-left:0">
 <input type="text" name="link['.$i.'][field1_'.$language['id_lang'].']" size="64" value="'.$this->_xml->link[$i]->{'field1_'.$language['id_lang']}.'" />
 <p style="clear: both"></p>
</div>';

 $output .= '
<label>'.$this->l('Field #2').'</label>
<div class="margin-form" style="padding-left:0">
 <input type="text" name="link['.$i.'][field2_'.$language['id_lang'].']" size="64" value="'.$this->_xml->link[$i]->{'field2_'.$language['id_lang']}.'" />
 <p style="clear: both"></p>
</div>';
 $output .= '</div>';

 }
 $output .= '</fieldset>';

 $output .= '
<div class="clear pspace"></div>
'.($i >= 0 ? '<a href="javascript:{}" onclick="removeDiv(\'item'.$i.'\')" style="color:#EA2E30"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="'.$this->l('delete').'" />'.$this->l('Delete this item').'</a>' : '').'
  <hr/></div>';
 return $output;
}
 private function _displayForm()
 {
	global $cookie;
	/* Languages preliminaries */
	$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
	$languages = Language::getLanguages();
	$iso = Language::getIsoById($defaultLanguage);
	$isoUser = Language::getIsoById(intval($cookie->id_lang));
/* xml loading */
$xml = false;
if (file_exists(dirname(__FILE__).'/links.xml'))
 if (!$xml = @simplexml_load_file(dirname(__FILE__).'/links.xml'))
  $this->_html .= $this->displayError($this->l('Your links file is empty.'));
	  $this->_html .= '
 <script type="text/javascript">
 function removeDiv(id)
 {
  $("#"+id).fadeOut("slow");
  $("#"+id).remove();
 }
 function cloneIt(cloneId) {
  var currentDiv = $(".item:last");
  var id = ($(currentDiv).size()) ? $(currentDiv).attr("id").match(/[0-9]/gi) : -1;
  var nextId = parseInt(id) + 1;
  $.get("'._MODULE_DIR_.$this->name.'/ajax.php?id="+nextId, function(data) {
$("#items").append(data);
  });
  $("#"+cloneId).remove();
 }
 </script>
 <form method="post" action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data">
  <fieldset style="width: 800px;">
	  <legend><img src="'.$this->_path.'logo.gif" alt="" title="" /> '.$this->displayName.'</legend>
 <div id="items">';
  $i = 0;
  foreach ($xml->link as $link)
  {
   $last = ($i == (count($xml->link)-1) ? true : false);
   $this->_html .= $this->_getFormItem($i, $last);
   $i++;
  }
  $this->_html .= '
</div>
<a id="clone'.$i.'" href="javascript:cloneIt(\'clone'.$i.'\')" style="color:#488E41"><img src="'._PS_ADMIN_IMG_.'add.gif" alt="'.$this->l('add').'" /><b>'.$this->l('Add a new item').'</b></a>';

 $this->_html .= '
<div class="margin-form clear">
 <div class="clear pspace"></div>
 <div class="margin-form">
   <input type="submit" name="submitUpdate" value="'.$this->l('Save').'" class="button" />
 </div>
</div>

</fieldset>
  </form>';
 }
 function hookTop($params)
 {
	global $cookie;
	/* Languages preliminaries */
	$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
	$languages = Language::getLanguages();
	$iso = Language::getIsoById($defaultLanguage);
	$isoUser = Language::getIsoById(intval($cookie->id_lang));
if (file_exists(dirname(__FILE__).'/links.xml'))
 if ($xml = simplexml_load_file(dirname(__FILE__).'/links.xml'))
 {
   global $cookie, $smarty;
$smarty->assign(array(
 'xml' => $xml,
 'field1' => 'field1_'.$cookie->id_lang,
 'field2' => 'field2_'.$cookie->id_lang,
 'this_path_tmpics' => $this->_path
));
return $this->display(__FILE__, 'tmpics.tpl');
  }
 return false;
 }
}
?>

Edited by Tekker (see edit history)
Link to comment
Share on other sites

Ok, I turned your code into a module and I guess I will be able to get it running if I'll have tmpics.tpl and a sample links.xml, as I currently have an error returned because it can't find links.xml file.

 

Like explained in PM, I'll send those files in PM, not that I care to much that people steal this module, TM won't help anyway,, but still ...

 

So PM send with those 2 files, they are kinda short.

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

Friends. I have the same problems with uploading images. Tell me if you found some solution

 

' [PrestaShop] Fatal error en el módulo tmnivoslider:

Llamado a checkImage undefined function () ",

Link to comment
Share on other sites

Problema solucionado!!!

 

esta es mi plantilla http://www.templatemonster.com/prestashop-themes/41565.html

Usa dos módulos que no son compatibles con la ultima versión de prestashop (tmpics,tmnivoslider)

 

' [PrestaShop] Fatal error en el módulo tmnivoslider:

Llamado a checkImage undefined function () ",

 

solution:

 

este error es debido a que todas las funciones de images.inc.php están en desuso

 

[*] Classes : images.inc.php functions are now all deprecated, use the new class ImageManager instead

 

ahora bien, podemos solucionar el problema actualizando todas las instancias de checkimage() a ImageManager::checkImageMemoryLimit(), lo cual es un trabajo realmente tedioso.

 

otra solución mas rápida y efectiva es usar de todos modos el archivo images.inc.php y todas sus funciones para esto simplemente pegamos esta linea de codigo:

 

require_once(_PS_ROOT_DIR_.'/images.inc.php');

 

en el archivo :

 

tu_sitio/config/autoload.php

 

Espero que les sea de utilidad! :D :D

Link to comment
Share on other sites

  • 4 weeks later...

My solution to correct the problem is to change the following lines :

 

- Line 69 : change if ($error = checkImage($_FILES['link_' . $i . '_img'], $this->maxImageSize))

 

by if ($error = ImageManager::validateUpload($_FILES['link_' . $i . '_img'], $this->maxImageSize))

 

 

- Line 73 : change elseif (!imageResize($tmpName, dirname(__FILE__) . '/slides/slide_0' . $i . '.jpg'))

 

 

by elseif (!ImageManager::resize($tmpName, dirname(__FILE__) . '/slides/slide_0' . $i . '.jpg'))

 

 

It is just working :mellow:

Edited by JulienZ (see edit history)
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...