Jump to content

Unzip a file in one of the prestashops folder


Recommended Posts

Hello everyone,

I am trying to upload a zip file into a folder of prestashop "csv_import" which I created beacuse I want to upload a csv of my products! Because the large size of csv the file must be zipped!! So when I upload it I want a module imports into my db after unzip the csv file. I tried these diferrent codes into one of the files of the module but doesn't work!

 

CODE 1 

/* $zip_file = 'http://blablabla/import_csv/prototype_csv.zip';

$zip = new ZipArchive;

$res = $zip->open($zip_file);

if ($res === TRUE) {

  $zip->extractTo('http://blablabla/import_csv/the_csv');

  $zip->close();

  echo 'woot!';

} else {

  echo 'doh!';

}*/

 

CODE 2

 

 $zip_file = _PS_ROOT_DIR_ . "/import_csv/prototype_csv.zip"; 

//$extract_dir = dirname(dirname(__FILE__)) . '/theCSV/';

//$file = dirname(dirname(__FILE__)) . '/theCSV/Eshop.csv';

//$file = $_FILES['filecsv'];

            if ($zip_file['error'] == 0) {

                //move_uploaded_file($csv['tmp_name'], dirname(__FILE__) . "/images/" . $img['name']);

                $zip = new ZipArchive;

                //$a = _PS_ROOT_DIR_ . "/import_csv/" . $zip_file;

                $res = $zip->open($zip_file);

                if ($res === true) {

                    $zip->extractTo(_PS_ROOT_DIR_ . '/the_csv');

                    $zip->close();

echo 'woot!';

                }

               else {

echo 'doh!';

  }

            }

 

thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More