Rrecently I'm creating a telegram bot using telegram Bot API. My plan is to place a single button in a page for uploading a specific folder's files, to telegram with cUrlFile uploading; so far, I'm done my work with uploading but my purpose is large-sized files. To do this I need to show user some kind of progress bar that shows user how much MBs or KBs Uploaded.
My upload function is looks something like this:
function sendFile($token,$photosArray,$chatsArray){
$ch = curl_init('https://api.telegram.org/bot'.$token.'/sendDocument');
$cfile = new CURLFile(realpath($photosArray['path']),'image/jpg',$photosArray['name']);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
foreach($chatsArray as $chatId){
$data = array('chat_id' => $chatId, 'document' => $cfile);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$res=curl_exec($ch);
}
return $res;
}
For now its works but I don't have any idea how can I get uploaded size from this curl and show it to user. of course i mean real-time progress bar. In other questions I found questions like : cURL download progress in PHP
But it's not my answer.
Whats I'm looking for is to do this:
1- Click on a button to upload a folder files
2- Upload one file at a time and show a live progress bar to user
3- When upload is completed, start uploading next file and show another progress bar for it and so on.
Is it needs to implemented by AJAX or something else? I'm pretty new in php so if someone can help me in a simple way I'll all ears.