Page 2 of 5

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Mon May 02, 2011 7:07 pm
by tiberii
Hello! :)
Why show me this error:

Image

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

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Tue May 03, 2011 11:23 pm
by alexmbra
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".

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 1:56 am
by gsk
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>'

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 2:47 am
by alexmbra
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  ///////////////////////////////
}
?>


Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 3:58 am
by gsk
The 100x100 image is created exactly there by this line:

Code: Select all

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

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 4:08 am
by gsk
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  ///////////////////////////////

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 4:15 am
by gsk
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.

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 5:53 am
by alexmbra
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/".

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 7:40 am
by alexmbra
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?

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed May 04, 2011 11:39 am
by alexmbra
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  ////////////////////}
?>


Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Thu May 05, 2011 7:15 am
by alexmbra
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;
}
?>



Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Sun May 15, 2011 10:27 pm
by sickboy
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?

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Mon May 16, 2011 2:53 am
by gsk
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.

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Wed Jun 01, 2011 9:54 pm
by Lazyfruit
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.

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Thu Jun 02, 2011 12:20 am
by gsk
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.

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Thu Jun 02, 2011 3:17 am
by Lazyfruit
Hey Thx for the quick reply, I got it working now perfectly and its gonna save a lot of time, much appreciated!

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Thu Jun 30, 2011 12:19 pm
by marcelwoo
Can you pls update it to fit opencart 1.5x? thx

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Fri Jul 08, 2011 5:42 pm
by gsk
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.

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Fri Jul 08, 2011 11:32 pm
by marcelwoo
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!

Re: [MOD]Rapid Image Uploader (image manager alternative)

Posted: Tue Jul 12, 2011 1:24 am
by maciek
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