function _drush_print_pdf_download_file in Printer, email and PDF versions 7
Same name and namespace in other branches
- 6 print_pdf/print_pdf.drush.inc \_drush_print_pdf_download_file()
Download a file using wget or curl
Adapted from a function in drush/includes/drush.inc to support 302 redirects.
Parameters
string $download_url: The path to the file to download
Return value
string The filename that was downloaded, or NULL if the file could not be downloaded.
1 call to _drush_print_pdf_download_file()
- drush_print_pdf_download in print_pdf/
print_pdf.drush.inc - Download and extract PDF archive.
File
- print_pdf/
print_pdf.drush.inc, line 188 - drush integration for print_pdf module PDF libraries download.
Code
function _drush_print_pdf_download_file($download_url) {
$wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
if (!drush_get_context('DRUSH_SIMULATE')) {
if ($wget_ret) {
// Get the filename of the saved file from the output
$wget_out = explode('"', array_shift(drush_shell_exec_output()));
$filename = $wget_out[1];
}
else {
$tempnam = uniqid('drush_print_pdf_');
$curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
if ($curl_ret) {
// File was donwloaded with the tempname
// Find the effective name
$filename = explode('/', array_shift(drush_shell_exec_output()));
$filename = array_pop($filename);
// Rename file from tempname to effective name
if (!drush_op('rename', $tempnam, './' . $filename)) {
$filename = $tempnam;
}
}
else {
$filename = FALSE;
}
}
}
else {
$filename = basename($download_url);
}
return $filename;
}