Jump to content

Unable to upload product image 1.6.0.8


manson84

Recommended Posts

Dear all,

 

I am unable to upload product images - images turn out to be a grey question mark. After turning on the debug mode, it shows "Unexpected token <" on the product page (see screenshot attached). 

 

I searched for similar issues like mine and tried their methods but so far nothing works. Such as this: http://www.prestashop.com/forums/topic/290297-uploading-products-images-issues/ 

 

The Img folder have been set to writable recursively. 

 

This is a show-stopper and I'm desperate to get this fixed soon. Any [spam-filter] please help? 

 

- Chris

 

 

 

 

post-429843-0-73393100-1414316108_thumb.jpg

Link to comment
Share on other sites

F12 > Console tab

 

Hi, it's showing:

 

Failed to load resource: the server responded with a status of 503 (temporarily overloaded) http://mywebsite.com/img/p/en-default-cart_default.jpg
 
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://mywebsite.com/admin/index.php?controller=AdminProducts&toke…cd53bd05abb9&ajax=1&id_product=1&action=addProductImage&rand=1414553060037
 
Doesn't look like a AJAX error yeah? Any idea what these mean?
Link to comment
Share on other sites

Now you know where to begin - /controllers/admin/AdminProducts.php, ajaxProcessaddProductImage().

 

I would use some IDE + XDebug or gradually deleted die() commands after every line in this method to find the exact line of failure.

Link to comment
Share on other sites

Hi PrestaShop Fanatic, 

 

Thanks for your kind advice. I'm not a programmer - only know the basics (don't really know how to debug!!). I'm pasting my codes here - hopefully can get some help from the experts to find the bug! 

 

File: controllers/admin/AdminProductsController.php

 

public function ajaxProcessaddProductImage()
{
self::$currentIndex = 'index.php?tab=AdminProducts';
$product = new Product((int)Tools::getValue('id_product'));
$legends = Tools::getValue('legend');
 
if (!is_array($legends))
$legends = (array)$legends;
 
if (!Validate::isLoadedObject($product))
{
$files = array();
$files[0]['error'] = Tools::displayError('Cannot add image because product creation failed.');
}
 
$image_uploader = new HelperImageUploader('file');
$image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size);
$files = $image_uploader->process();
 
foreach ($files as &$file)
{
$image = new Image();
$image->id_product = (int)($product->id);
$image->position = Image::getHighestPosition($product->id) + 1;
 
foreach ($legends as $key => $legend)
if (!empty($legend))
$image->legend[(int)$key] = $legend;
 
if (!Image::getCover($image->id_product))
$image->cover = 1;
else
$image->cover = 0;
 
if (($validate = $image->validateFieldsLang(false, true)) !== true)
$file['error'] = Tools::displayError($validate);
 
if (isset($file['error']) && (!is_numeric($file['error']) || $file['error'] != 0))
continue;
 
if (!$image->add())
$file['error'] = Tools::displayError('Error while creating additional image');
else
{
if (!$new_path = $image->getPathForCreation())
{
$file['error'] = Tools::displayError('An error occurred during new folder creation');
continue;
}
 
$error = 0;
 
if (!ImageManager::resize($file['save_path'], $new_path.'.'.$image->image_format, null, null, 'jpg', false, $error))
{
switch ($error)
{
case ImageManager::ERROR_FILE_NOT_EXIST :
$file['error'] = Tools::displayError('An error occurred while copying image, the file does not exist anymore.');
break;
 
case ImageManager::ERROR_FILE_WIDTH :
$file['error'] = Tools::displayError('An error occurred while copying image, the file width is 0px.');
break;
 
case ImageManager::ERROR_MEMORY_LIMIT :
$file['error'] = Tools::displayError('An error occurred while copying image, check your memory limit.');
break;
 
default:
$file['error'] = Tools::displayError('An error occurred while copying image.');
break;
}
continue;
}
else
{
$imagesTypes = ImageType::getImagesTypes('products');
foreach ($imagesTypes as $imageType)
{
if (!ImageManager::resize($file['save_path'], $new_path.'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
{
$file['error'] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']);
continue;
}
}
}
 
unlink($file['save_path']);
//Necesary to prevent hacking
unset($file['save_path']);
Hook::exec('actionWatermark', array('id_image' => $image->id, 'id_product' => $product->id));
 
if (!$image->update())
{
$file['error'] = Tools::displayError('Error while updating status');
continue;
}
 
// Associate image to shop from context
$shops = Shop::getContextListShopID();
$image->associateTo($shops);
$json_shops = array();
 
foreach ($shops as $id_shop)
$json_shops[$id_shop] = true;
 
$file['status']   = 'ok';
$file['id']       = $image->id;
$file['position'] = $image->position;
$file['cover']    = $image->cover;
$file['legend']   = $image->legend;
$file['path']     = $image->getExistingImgPath();
$file['shops']    = $json_shops;
 
@unlink(_PS_TMP_IMG_DIR_.'product_'.(int)$product->id.'.jpg');
@unlink(_PS_TMP_IMG_DIR_.'product_mini_'.(int)$product->id.'_'.$this->context->shop->id.'.jpg');
}
}
 
die(Tools::jsonEncode(array($image_uploader->getName() => $files)));
}
Link to comment
Share on other sites

Hi,

 

Coming back with updated error messages that are displaying in my chrome console while trying to upload the product image again:

 

=======================

Resource interpreted as Image but transferred with MIME type application/javascript: "http://mywebsite.com/admin/themes/default/js/vendor/enquire.min.js". 
 
Resource interpreted as Image but transferred with MIME type application/javascript: "http://mywebsite.com/admin/themes/default/js/admin-
theme.js". modernizr.min.js:
 
GET http://mywebsite.com/43-small_default/faded-short-sleeve-tshirts.jpg 404 (Not Found) index.php?controller=AdminProducts&id_product=1&updateproduct&token=b1bcaa92f11ffaf69eb8cd53bd05abb9:1651
 
GET http://mywebsite.com/img/p/4/3/43-cart_default.jpg 404 (Not Found) jquery-1.11.0.min.js:3
GET http://mywebsite.com/img/p/en-default-cart_default.jpg 404 (Not Found) jquery-1.11.0.min.js:3
=======================
 
Does it look like I'm missing some files here? Or that there were some broken links? I'm not using the default prestashop theme, but a 3rd party one. 
Link to comment
Share on other sites

Hi everyone,

 

Just a quick update on this issue. I did a clean re-install and noticed that the same problem still exists (definitely not caused by 3rd party template). Instead of further complicating the situation, i decided to trim the file size (from 1MB to a few KB) and tah-dah...it's working now. 

 

Link to comment
Share on other sites

×
×
  • Create New...