The download process is done with da_download_attachment function located in plugin folder/includes/functions.php
You’d have to chek what is the filepath you have in this function, right at the top 3 lines (print_r or sth):
$filepath = $uploads['basedir'] . '/' . $attachment;
There’s a filter hook to modify the filepath if needed, but in any case you have to know what is the filepath there.
This can definitely be solved.
Thread Starter
Nisr
(@nisr)
thanks for replying 🙂
ok let me be more clear,
the code that i use will put attachments in different upload directories according to each post type. this means, for the publications post type, the attachments will be uploaded to :
/wp-content/uploads/publications/file2.pdf
while for the communications post type they will be uploaded to :
/wp-content/uploads/communications/file3.pdf
So, i need the plugin to make visitors able to download these attachments from any upload directory where they were uploaded to.
i hope you can try the code in any theme function.php and tell me what i have to do. because i looked inside the plugin function.php and i found the line you mentioned but i really didn’t know what to do.
function da_download_attachment($attachment_id = 0)
{
if(get_post_type($attachment_id) === 'attachment')
{
$uploads = wp_upload_dir();
$attachment = get_post_meta($attachment_id, '_wp_attached_file', true);
$filepath = $uploads['basedir'].'/'.$attachment;
if(!file_exists($filepath) || !is_readable($filepath))
return false;
// if filename contains folders
if(($position = strrpos($attachment, '/', 0)) !== false)
$filename = substr($attachment, $position + 1);
else
$filename = $attachment;
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 0);
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename='.rawurldecode($filename));
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Cache-control: private');
header('Pragma: private');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Length: '.filesize($filepath));
if($filepath = fopen($filepath, 'rb'))
{
while(!feof($filepath) && (!connection_aborted()))
{
echo fread($filepath, 1048576);
flush();
}
fclose($filepath);
}
else
return false;
update_post_meta($attachment_id, '_da_downloads', (int)get_post_meta($attachment_id, '_da_downloads', true) + 1);
exit;
}
else
return false;
}
waiting for your reply
best regards