How to download a file and use it for import operations in php

75 views Asked by At

I'm trying to automate the import of a product catalog for my ecommerce and i'm wondering if it is possible to download the file remotely and use it directly from code without first downloading it manually and then import it. This is the portion of code where the addon sets the paths, if i could just add some code to download the file and place it in the "csv_upload_folder" before the import i think it can work perfectly

define('CSV_IMPORT_FOLDER', 'csv_import/');
define('CSV_IMPORT_INI_FILE', CSV_IMPORT_FOLDER . 'csv_import.ini');
$config = parse_ini_file(CSV_IMPORT_INI_FILE, true);

define("CORRECT_FIELDS_COUNT", (isset($config["settings"]["correct_fields_count"]) && $config["settings"]["correct_fields_count"] == 1)); 

define('CSV_IMPORT_UPLOAD_FOLDER', CSV_IMPORT_FOLDER . $config["settings"]["csv_upload_folder"] . '/');
define('CSV_IMPORT_PHP_FILE', basename($PHP_SELF));
define('CSV_DEBUG', (isset($config["settings"]["debug"]) && $config["settings"]["debug"]));

This Code is part of the "easy csv import" by "cozmo"

Thank You

1

There are 1 answers

0
Mariano On BEST ANSWER

I managed to do it, i used file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r')); to download the file in the same dir of the script