Last active
March 12, 2024 20:52
-
-
Save trey8611/6fbf6d36b5b86068d86253ccf934eb55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
################### READ ME ################################# | |
You'll pass the URL to your feed/file to this function inside the "Download from URL" option when creating an import. | |
Image examples: https://d.pr/hCfNek and https://d.pr/MnerNb. | |
1. [custom_file_download("ftp://username:[email protected]/full/path/to/file.csv","csv")] | |
2. [custom_file_download("http://example.com/full/path/to/file.csv","csv")] | |
You must add the code for the function inside your themes functions.php file, or in a plugin like Code Snippets. | |
This code is provided in the hope that it helps, but without any support. | |
############################################################### | |
*/ | |
// Programmatically download and return import file via URL. | |
function custom_file_download($url, $type = 'xml'){ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); | |
/* Optional: Set headers... | |
* $headers = array(); | |
* $headers[] = "Accept-Language: de"; | |
* curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
*/ | |
$result = curl_exec($ch); | |
if (curl_errno($ch)) { | |
exit('Error:' . curl_error($ch)); | |
} | |
curl_close ($ch); | |
$uploads = wp_upload_dir(); | |
$filename = $uploads['basedir'] . '/' . strtok(basename($url), "?") . '.' . $type; | |
if (file_exists($filename)){ | |
@unlink($filename); | |
} | |
file_put_contents($filename, $result); | |
return str_replace($uploads['basedir'], $uploads['baseurl'], $filename); | |
} |
Thanks - removing the space did the trick!
…On Mon, 9 Mar 2020 at 20:05, Trey ***@***.***> wrote:
I've updated the gist, there could be errors if there's a space after the
comma in the function call. It should be like this:
[custom_file_download("
***@***.***/full/path/to/file.csv","csv")]
Also, we only provide support here: http://www.wpallimport.com/support/.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6fbf6d36b5b86068d86253ccf934eb55?email_source=notifications&email_token=AOXDI6QYLKM3FGUHUGU3ZTTRGVDZ5A5CNFSM4I7TCN32YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAGDVMI#gistcomment-3205828>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOXDI6UNB7UUSHWJHGJQPHTRGVDZ5ANCNFSM4I7TCN3Q>
.
--
To unsubscribe from this group and stop receiving emails from it, send an
email to ***@***.***
I have removed space after the comma in the function call but still not working. It is just showing "error:" letter but not showing what was the error
I tried this and still get: <RETS ReplyCode="20513" ReplyText="Miscellaneous Error: Missing required User-Agent request header. See the 'Required Client Request Header Fields' section in the RETS specification."/>
The final URL that it generated was a little off on the shared hosting account I was using, but besides that this gist worked wonderfully to comply with Airtable's new API requirements.
Thanks for sharing. I see that it also now appears on WP All Import's website: https://www.wpallimport.com/documentation/code-snippets/#workaround-for-importing-from-ftp for anyone who that might help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the gist, there could be errors if there's a space after the comma in the function call. It should be like this:
[custom_file_download("ftp://username:[email protected]/full/path/to/file.csv","csv")]
Also, we only provide support here: http://www.wpallimport.com/support/.