Post by tiberii » Mon May 02, 2011 7:07 pm

Hello! :)
Why show me this error:

Image

http://prikachi.com/images/438/3292438h.png

Newbie

Posts

Joined
Sun Apr 24, 2011 7:46 pm

Post by alexmbra » Tue May 03, 2011 11:23 pm

Does anyone have any idea of how could I change the folder to where the image files go?

I tried to change this:

Code: Select all

$uploads_dir = "../../../image/data/";
and this:

Code: Select all

 $image_dir = "../../../image/data/";
 $cache_dir = "../../../image/cache/data/";
To have a "produtos/" directory, but this is not working. Like this:

Code: Select all

$uploads_dir = "../../../image/data/produtos/";
and this:

Code: Select all

 $image_dir = "../../../image/data/produtos/";
 $cache_dir = "../../../image/cache/data/produtos/";
But looking at the database, the images get save as: "data/myImage.jpg".

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


New member

Posts

Joined
Wed Dec 15, 2010 3:52 am

Post by gsk » Wed May 04, 2011 1:56 am

With the changes you did, images physically are uploaded to 'image/data/produtos/', but database records are not updated.
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>'
with

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

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by alexmbra » Wed May 04, 2011 2:47 am

Well, I manage to make it work more or less, by changing the "admin\controller\common\agile_uploader.php" file. Like bellow. And I need this way, because I have several diferent folders for my products' images. And after making this to work, I will be able to create a way to choose the destination folder.

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


New member

Posts

Joined
Wed Dec 15, 2010 3:52 am

Post by gsk » Wed May 04, 2011 3:58 am

The 100x100 image is created exactly there by this line:

Code: Select all

$myimage->save($cache_dir . $new_image);

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by gsk » Wed May 04, 2011 4:08 am

I think you have messed up things a bit altering the dir_names.
For example you should not change

Code: Select all

return $info['basename'];

to

Code: Select all

return $tempPathName;///// changes  ///////////////////////////////

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by gsk » Wed May 04, 2011 4:15 am

Just to give you a hint,

Code: Select all

array_push($myFiles, resize($uploads_dir.$name, 100, 100));
does 2 things:
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.

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by alexmbra » Wed May 04, 2011 5:53 am

But for some reason, the resize funcion is not working. Because after uploading, I can find the original file inside "image/data/produtos/", but not the 100x100 file inside "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


New member

Posts

Joined
Wed Dec 15, 2010 3:52 am

Post by alexmbra » Wed May 04, 2011 7:40 am

Also, the resize function test this first:

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);
    }
before returning the file. So,it will never resize and create a new image right?

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


New member

Posts

Joined
Wed Dec 15, 2010 3:52 am

Post by alexmbra » Wed May 04, 2011 11:39 am

Well, I found out more or less the reason because is not working.

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;
The code starts to work if I change it to:

Code: Select all

$uploads_dir = "../../../image/data/produtos/";
...
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/" ;
Also, the folder "produtos" needs to already exists inside the cache of the created file won't be saved there.

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


New member

Posts

Joined
Wed Dec 15, 2010 3:52 am

Post by alexmbra » Thu May 05, 2011 7:15 am

Well, finally I manage to make it work. The problem was the scope of variable. I was forgetting to use the global inside the function resize.
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


New member

Posts

Joined
Wed Dec 15, 2010 3:52 am

Post by sickboy » Sun May 15, 2011 10:27 pm

Hi GSK,

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?

Newbie

Posts

Joined
Thu Dec 30, 2010 9:59 pm

Post by gsk » Mon May 16, 2011 2:53 am

Hi sickboy,

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.

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by Lazyfruit » Wed Jun 01, 2011 9:54 pm

Hi

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.

Newbie

Posts

Joined
Wed Apr 13, 2011 5:39 pm

Post by gsk » Thu Jun 02, 2011 12:20 am

You should just overwrite the entire admin and catalog folders over the original ones, as for any modification except vqmod (provided you have not made any other modifications on these files, as this will break them). What you did is not wrong, it should work, but you probably did not overwrite any files. Just try again.

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by Lazyfruit » Thu Jun 02, 2011 3:17 am

Hey Thx for the quick reply, I got it working now perfectly and its gonna save a lot of time, much appreciated!

Newbie

Posts

Joined
Wed Apr 13, 2011 5:39 pm

Post by marcelwoo » Thu Jun 30, 2011 12:19 pm

Can you pls update it to fit opencart 1.5x? thx

"We help each other to grow". That's the opencart community!

All free mods
Home Based Ebay business Opportunity(not ads)


User avatar
Active Member

Posts

Joined
Tue Mar 29, 2011 1:45 am

Post by gsk » Fri Jul 08, 2011 5:42 pm

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.

gsk
New member

Posts

Joined
Mon Apr 04, 2011 1:46 am

Post by marcelwoo » Fri Jul 08, 2011 11:32 pm

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.

8) 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)


User avatar
Active Member

Posts

Joined
Tue Mar 29, 2011 1:45 am

Post by maciek » Tue Jul 12, 2011 1:24 am

Hi GSK,

I see that you have done a really good job with this image uploader.
Have managed to sort it out for 1.5.0.5 yet?

thanks

Newbie

Posts

Joined
Fri Jul 08, 2011 9:32 pm

Who is online

Users browsing this forum: No registered users and 54 guests