Post by nureddin21 » Fri Mar 18, 2022 5:24 pm

Hello everyone.
Can anyone help or hint with this question..

Any feedback is greatly appreciated..
Version 3.0.3.8

Thank you.
Last edited by nureddin21 on Wed Mar 23, 2022 4:01 am, edited 1 time in total.

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by mikeinterserv » Fri Mar 18, 2022 10:55 pm

So what, you have all the images in a downloadable zip file or you expect to scrape all the images off the page.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by nureddin21 » Fri Mar 18, 2022 11:01 pm

mikeinterserv wrote:
Fri Mar 18, 2022 10:55 pm
So what, you have all the images in a downloadable zip file or you expect to scrape all the images off the page.
I got this code but it doesn't work..
I want to download all product images (either zip file or download them without compression)

Code: Select all

public function downloadcatalog(){
$this->load->model('catalog/product'); 
        $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);        
        $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);        
            foreach ($results as $result) {
                $files[] = 'image/'.$result['image'];
            }         
        $zip = new ZipArchive();        
        # create a temp file & open it
        $tmp_file = tempnam('.', '');
        $zip->open($tmp_file, ZipArchive::CREATE);        
        # loop through each file
        foreach ($files as $file) {
            # download file
            $download_file = file_get_contents($file);
            #add it to the zip
            $zip->addFromString(basename($file), $download_file);
        }
        # close zip
        $zip->close();
        $file_name = $product_info['name'].'.zip';
        # send the file to the browser as a download
        /*header('Content-disposition: attachment; filename="'.$product_info['name'].'"');
        header('Content-type: application/zip');*/
        header("HTTP/1.1 200 OK");
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-type: application/zip");
        header('Content-Disposition: attachment; filename="'.$file_name.'"');
        header("Content-Transfer-Encoding: binary");
        header('Content-Length: ' . filesize($tmp_file));

        //$zip->close();
        //readfile($zipname);
                readfile($tmp_file);
                unlink($tmp_file);
            }
The problem with this code is that it downloads an empty zip file

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by mikeinterserv » Sat Mar 19, 2022 12:14 am

See below
Last edited by mikeinterserv on Sat Mar 19, 2022 12:20 am, edited 1 time in total.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by mikeinterserv » Sat Mar 19, 2022 12:16 am

file_get_contents($file);

The problem with this code is that it downloads an empty zip file
Here in bold you are trying to get the FILE CONTENTS and NOT the file - If it were a text file the contents would be the txt.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by by mona » Sat Mar 19, 2022 12:41 am

FYI : It is true that maybe someone from the “community” will assist, however the question has no valid community benefit and is outside of the scope of free support. The purpose of the forum is not to be abused for personal benefit but to be of general use to the community as a whole. Maybe consider adapting your question to be of community benefit and adapt the answer to your personal use ?

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by mikeinterserv » Sat Mar 19, 2022 1:05 am

Well I would say this code is not what you want.
There is a LOT wrong with the code you have posted.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by cmsroom » Sat Mar 19, 2022 4:28 am

nureddin21 wrote:
Fri Mar 18, 2022 5:24 pm
Hello everyone.
Can anyone help or hint with this question..

Any feedback is greatly appreciated..
Version 3.0.3.8

Thank you.
You can use Extension https://www.opencart.com/index.php?rout ... n_id=43489

You may like these extension : - https://www.opencart.com/index.php?rout ... r=cmsrooms


New member

Posts

Joined
Fri Sep 28, 2018 1:37 am

Post by mikeinterserv » Tue Mar 22, 2022 6:23 am

Try this mines FREE
Your previous code only attempted to get the additional images.
This gets the main image plus all additional images. I will make it into an Extension and post it here later.
YES it downloads the ORIGINAL IMAGES as uploaded - NOT the cached versions
To download the images WITHOUT FOLDERS so the zip contains JUST the images change line.

Code: Select all

$zip->addFile($file));
To:

Code: Select all

$zip->addFile($file, basename($file));
.

Code: Select all

public function downloadcatalog(){
$this->load->model('catalog/product'); 
        $product_info = $this->model_catalog_product->getProduct((int)$this->request->get['product_id']);        
        $results = $this->model_catalog_product->getProductImages((int)$this->request->get['product_id']);        

			foreach ($results as $result) {
				$files[] ='image/'.$result['image'];
			}

			$files[] ='image/'.$product_info['image'];
	
		$zip = new ZipArchive;

		$zip_name = $product_info['name'].'.zip';
 
		if ($zip->open($zip_name, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === TRUE){

			foreach ($files as $file) {
			$zip->addFile($file);
			}
			$zip->close();
	        	} 
		if (file_exists($zip_name)) {
			header('Content-Description: File Transfer');
			header('Content-Type: application/octet-stream');
			header('Content-Disposition: attachment; filename="' . basename($zip_name) . '"');
			header('Expires: 0');
			header('Cache-Control: must-revalidate');
			header('Pragma: public');
			header('Content-Length: ' . filesize($zip_name));
			readfile($zip_name);
			unlink($zip_name);
			exit;
		}
	}
Last edited by mikeinterserv on Wed Mar 23, 2022 4:27 am, edited 3 times in total.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by straightlight » Tue Mar 22, 2022 7:55 am

It could also be done with an Event by using a button to download. In addition:

Code: Select all

$this->request->get['product_id']
instances should all be changed to:

Code: Select all

(int)$this->request->get['product_id']

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by mikeinterserv » Tue Mar 22, 2022 8:04 am

Yes that's what I was thinking also.
I will add the (int) - Thanks

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by nureddin21 » Tue Mar 22, 2022 5:53 pm

mikeinterserv wrote:
Tue Mar 22, 2022 6:23 am
This gets the main image plus all additional images. I will make it into an Extension and post it here later.
Thank you, but I tried the last code and it only exports the main image.. I think Maybe it does not enter to the first "foreach" ..

Another question, please.. Is it possible to export all product images without compressing them?

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by mikeinterserv » Tue Mar 22, 2022 11:06 pm

I think Maybe it does not enter to the first "foreach"
Well it does,

What do you mean - It has been tested and works perfectly for ALL product images.
It means you have NO additional images if you do not see them added to the zip

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by nureddin21 » Wed Mar 23, 2022 2:05 am

mikeinterserv wrote:
Tue Mar 22, 2022 11:06 pm
I think Maybe it does not enter to the first "foreach"
Well it does,

What do you mean - It has been tested and works perfectly for ALL product images.
It means you have NO additional images if you do not see them added to the zip
Yes, you are right, I tested it with the default template and it works perfectly, but with Journal3 ??? , it does export the main image only... and I don't know why

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by mikeinterserv » Wed Mar 23, 2022 2:13 am

nureddin21 wrote:
Wed Mar 23, 2022 2:05 am
Yes, you are right, I tested it with the default template and it works perfectly, but with Journal3 ??? , it does export the main image only... and I don't know why
Well journal is unsupported and personally I have NO IDEA what journal does thats different.
I would have to see the source code of the product page to see whats different.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by nureddin21 » Wed Mar 23, 2022 2:17 am

mikeinterserv wrote:
Wed Mar 23, 2022 2:13 am
nureddin21 wrote:
Wed Mar 23, 2022 2:05 am
Yes, you are right, I tested it with the default template and it works perfectly, but with Journal3 ??? , it does export the main image only... and I don't know why
Well journal is unsupported and personally I have NO IDEA what journal does thats different.
I would have to see the source code of the product page to see whats different.
Yes, I know that the journal theme is not compatible with the standards and is unsupported here, etc.

But there is no difference in Controller file between both templates
So where could the problem be?

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by mikeinterserv » Wed Mar 23, 2022 2:19 am

nureddin21 wrote:
Wed Mar 23, 2022 2:17 am
But there is no difference in Controller file between both templates
So where could the problem be?
Of course there is a difference otherwise it would work
Give me the product.php as an attachment here.
catalog/controller/product/product.php

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by nureddin21 » Wed Mar 23, 2022 3:51 am

mikeinterserv wrote:
Wed Mar 23, 2022 2:19 am
nureddin21 wrote:
Wed Mar 23, 2022 2:17 am
But there is no difference in Controller file between both templates
So where could the problem be?
Of course there is a difference otherwise it would work
Give me the product.php as an attachment here.
catalog/controller/product/product.php
Aoo good even though I am not a programmer but I kept trying until I got to the solution and let me post it here ..
In addition to what you mentioned, there is a slight modification In the catalog/model/journal3/product.php file
add

Code: Select all

public function getProductImages($product_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order ASC");

		return $query->rows;
	}
Then add the following to the previous Controller file

Code: Select all

$this->load->model('journal3/product');
then edit

Code: Select all

$results = $this->model_catalog_product->getProductImages((int)$this->request->get['product_id']);

to

Code: Select all

$results = $this->model_journal3_product->getProductImages($this->request->get['product_id']);
Also add

Code: Select all

unlink($zip_name);
To delete files after downloading ...

It works perfectly for me
And just there trying to download the images without having to compress them.

New member

Posts

Joined
Tue Feb 23, 2021 2:48 am

Post by mikeinterserv » Wed Mar 23, 2022 4:28 am

nureddin21 wrote:
Wed Mar 23, 2022 3:51 am
It works perfectly for me
And just there trying to download the images without having to compress them.
Good I am glad you have it working now.
Sorry I forgot unlink, I have added it now.

Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales

Post by mikeinterserv » Sun Mar 27, 2022 12:36 am

Here is an OCmod based on EVENTS for product images download.
Installs as a MODULE in extensions/modules. You can install / uninstall from there.
Gets the ORIGINAL images as uploaded, zips and automatically downloads.
This is the code provided earlier in a Mod.
.

Attachments


Active Member

Posts

Joined
Thu May 28, 2020 6:55 am
Location - Wales
Who is online

Users browsing this forum: lockiedownunder and 25 guests