I tried to change this:
Code: Select all
$uploads_dir = "../../../image/data/";
Code: Select all
$image_dir = "../../../image/data/";
$cache_dir = "../../../image/cache/data/";
Code: Select all
$uploads_dir = "../../../image/data/produtos/";
Code: Select all
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/";
Flash Ctt Tracking V2
Animated Flash Header Banner V3
Animated Flash Banner V2
Rastreamento de envios pelo CTT correios
Flash Expandable Category Side Menu module
Flash Category Side Menu Module
Flash Cart Steps Module
Animated Flash Banner Module
Animated Flash HEADER Banner Module
You also need to alter the file admin/view/template/catalog/product_form.tpl
Find the javascript function 'addImages' near the end of the file and specifically
replace
Code: Select all
html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="data/' + image_name +'" id="image' + image_row + '" /><img src="<?php echo $image_path; ?>' + 'cache/data/' + im_thumb + '" alt="" id="preview' + image_row + '" class="image" onclick="image_upload(\'image' + image_row + '\', \'preview' + image_row + '\');" /></td>';
html += '<td class="left"><input type="radio" name="image" value="data/' + image_name +'" id="image" /></td>'
Code: Select all
html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="data/produtos/' + image_name +'" id="image' + image_row + '" /><img src="<?php echo $image_path; ?>' + 'cache/data/produtos/' + im_thumb + '" alt="" id="preview' + image_row + '" class="image" onclick="image_upload(\'image' + image_row + '\', \'preview' + image_row + '\');" /></td>';
html += '<td class="left"><input type="radio" name="image" value="data/produtos/' + image_name +'" id="image" /></td>'
The problem is that the resized 100x100 image is not been created inside the "cache/data/produtos/" after uploading. So, after uploading I can not see the image. But, after saving the product, the 100x100 image is created, by opencart and I will be able to see it.
So, the code that should be creating a 100x100 image, is not working here.
Do you have any idea?
Code: Select all
<?php
$uploads_dir = "../../../image/data/";
$produts_dir = "produtos/";///// changes //////////////////////////////
$uploads_dir = $uploads_dir . $produts_dir;///// changes ////////////////////////////
$myFiles = array();
if(count($_FILES["Filedata"]["error"]) < 2) {
// Single file
$tmp_name = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
} else {
// Multiple files
foreach ($_FILES["Filedata"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];
$name = $_FILES["Filedata"]["name"][$key];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
}
}
//echo 'RETURN DATA!';
echo implode(';', $myFiles);
function resize($filename, $width, $height)
{
require_once('../../../system/library/image.php');
$image_dir = "../../../image/data/";
$cache_dir = "../../../image/cache/data/";
$image_dir = $image_dir . $produts_dir;///// changes /////////////////////////////
$cache_dir = $cache_dir . $produts_dir;///// changes ///////////////////////
$info = pathinfo($filename);
$extension = $info['extension'];
$new_image = substr($info['filename'], 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
///// changes ///////////////////////////
$tempPath = substr($info['dirname'], strlen($image_dir));
$tempPathName = $tempPath . '/' . $info['basename'];
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
//return $info['basename'];
return $tempPathName;///// changes ///////////////////////////////
}
?>
Flash Ctt Tracking V2
Animated Flash Header Banner V3
Animated Flash Banner V2
Rastreamento de envios pelo CTT correios
Flash Expandable Category Side Menu module
Flash Category Side Menu Module
Flash Cart Steps Module
Animated Flash Banner Module
Animated Flash HEADER Banner Module
Code: Select all
$myimage->save($cache_dir . $new_image);
For example you should not change
Code: Select all
return $info['basename'];
to
Code: Select all
return $tempPathName;///// changes ///////////////////////////////
Code: Select all
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
It pushes the original filename value (that is returned from the resize function) to the array $myfiles, and resizes the image to 100x100 saving it to the proper cache dir.
Flash Ctt Tracking V2
Animated Flash Header Banner V3
Animated Flash Banner V2
Rastreamento de envios pelo CTT correios
Flash Expandable Category Side Menu module
Flash Category Side Menu Module
Flash Cart Steps Module
Animated Flash Banner Module
Animated Flash HEADER Banner Module
Code: Select all
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
Flash Ctt Tracking V2
Animated Flash Header Banner V3
Animated Flash Banner V2
Rastreamento de envios pelo CTT correios
Flash Expandable Category Side Menu module
Flash Category Side Menu Module
Flash Cart Steps Module
Animated Flash Banner Module
Animated Flash HEADER Banner Module
For some reason this concatenation is not working:
Code: Select all
$uploads_dir = "../../../image/data/";
$produts_dir = "produtos/";
$uploads_dir = $uploads_dir . $produts_dir;
...
$image_dir = "../../../image/data/" . $produts_dir;
$cache_dir = "../../../image/cache/data/" . $produts_dir;
Code: Select all
$uploads_dir = "../../../image/data/produtos/";
...
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/" ;
Do you have any idea of why this is happening?
I need this code to have dynamic paths and not hardcoded.
Thanks
Anyway, here is the code that works:
Code: Select all
<?php
$uploads_dir = "../../../image/data/produtos/";
$myFiles = array();
if(count($_FILES["Filedata"]["error"]) < 2)
{
// Single file
$tmp_name = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
else
{
// Multiple files
foreach ($_FILES["Filedata"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];
$name = $_FILES["Filedata"]["name"][$key];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
}
}
//echo 'RETURN DATA!';
echo implode(';', $myFiles);
function resize($filename, $width, $height)
{
require_once('../../../system/library/image.php');
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/";
$info = pathinfo($filename);
$extension = $info['extension'];
$new_image = substr($info['filename'], 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
$tempPathName = "produtos/" . $info['basename'];
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
//return $info['basename'];
return $tempPathName;///// changes ////////////////////}
?>
Flash Ctt Tracking V2
Animated Flash Header Banner V3
Animated Flash Banner V2
Rastreamento de envios pelo CTT correios
Flash Expandable Category Side Menu module
Flash Category Side Menu Module
Flash Cart Steps Module
Animated Flash Banner Module
Animated Flash HEADER Banner Module
Now, the only think missing is to get the directories inside the Data folder and put it on a list, to allow the destination of uploading, replacing $productDir.
Here is the "agile_uploader.php" file:
Code: Select all
<?php
$productDir = 'products/';
$uploads_dir = '../../../image/data/' . $productDir;
$myFiles = array();
if(count($_FILES["Filedata"]["error"]) < 2)
{
// Single file
$tmp_name = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext))
{
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
else
{
// Multiple files
foreach ($_FILES["Filedata"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];
$name = $_FILES["Filedata"]["name"][$key];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext))
{
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
}
}
//echo 'RETURN DATA!';
echo implode(';', $myFiles);
function resize($filename, $width, $height)
{
require_once('../../../system/library/image.php');
global $productDir;
$image_dir = '../../../image/data/' . $productDir;
$cache_dir = '../../../image/cache/data/' . $productDir;
$info = pathinfo($filename);
$extension = $info['extension'];
$new_image = substr($info['filename'], 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if(!file_exists($cache_dir))
{
mkdir($cache_dir );
}
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
$tempPathName = $productDir . $info['basename'];
return $tempPathName;
}
?>
Flash Ctt Tracking V2
Animated Flash Header Banner V3
Animated Flash Banner V2
Rastreamento de envios pelo CTT correios
Flash Expandable Category Side Menu module
Flash Category Side Menu Module
Flash Cart Steps Module
Animated Flash Banner Module
Animated Flash HEADER Banner Module
Thank you for this great MOD!
I got one issue and one question:
- i have uploaded 6000 products with the correct path for the main image en the other images.
This works fine in the front-end of the shop, but not in the back-end. With your MOD, the main image
is not displayed in the image tab.
When i upload an image with your MOD, the main image will be displayed correctly.
Do you have an idea how i can solve this?
- Is it possible to choose images that are allready on the server as fast with your tool instead of the image manager?
Thank for your kind words!
Let me explain why you are facing this issue:
Using this MOD, when you add images to products, all of these image filenames are stored in the product_image table, and when you choose the default image, this updates the main product image in the product table.
With the default OC functionality this does not happen. The default image is stored in the product table and all other images are stored in the product_image table.
This is why you are facing this issue.
So, what is needed, is another record for each product in the product_image table...not an easy task for 6000 products, except if you used some kind of script to import them all to database.
Regarding your question, unfortunately cannot be done, as it is a client side script. You can only upload images to the server, not those that are already there.
I hope I have helped.
To install this do I just upload the files (not the folder) to the admin section on my server and thats it it should work. I tried it but nothing is different when I go to add additonal images. I just get the normal image uploader.
"We help each other to grow". That's the opencart community!
All free mods
Home Based Ebay business Opportunity(not ads)
gsk wrote:Hi,
I will probably make it a vqmod, so you could apply it to all 1.5.x revisions.
Probably next week, if I manage to get some free time.
Hi,gsk. Thank you so much!
"We help each other to grow". That's the opencart community!
All free mods
Home Based Ebay business Opportunity(not ads)
Users browsing this forum: No registered users and 54 guests