Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function filesizecurl($arquivo)
  2. {
  3. if (is_file($arquivo) === false) {
  4. return false;
  5. }
  6.  
  7. $arquivo = realpath(preg_replace('#^file:#', '', $arquivo));
  8.  
  9. $ch = curl_init('file://' . ltrim($arquivo, '/'));
  10.  
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Faz o retorno ser salvo na variável
  12. curl_setopt($ch, CURLOPT_HEADER, 1); //Faz retornar os headers
  13. curl_setopt($ch, CURLOPT_NOBODY, 1); //Evita retornar o corpo
  14.  
  15. $headers = curl_exec($ch);
  16. curl_close($ch);
  17.  
  18. $ch = null;
  19.  
  20. //Com preg_match extraímos o tamanho retornado de Content-Length
  21. if (preg_match('#(^c|sc)ontent-length:(s|)(d+)#i', $headers, $matches) > 0) {
  22. return $matches[3];
  23. }
  24.  
  25. return false;
  26. }
  27.  
  28. $file_path = DIR_ARQUIVOS.$key.'.zip';
  29. $file_name = $key.'.zip';
  30. $new_name = $sql->getKeyName($key);
  31.  
  32. $sql->addDownloadQuantityFile($key);
  33.  
  34. set_time_limit(0);
  35.  
  36. header('Content-Type: "application/zip"');
  37. header('Content-Disposition: attachment; filename="'.basename($file_path).'"');
  38. header("Content-Transfer-Encoding: binary");
  39. header('Expires: 0');
  40. header('Pragma: no-cache');
  41. // Envia o arquivo para o cliente
  42. readfile($file_name);
  43.  
  44. if (preg_match('#pages/download.php$#', $pag) > 0)
  45. {
  46. include $pag;
  47. exit;
  48. }
  49.  
  50. header('Content-Type: "application/zip"');
  51. header('Content-Disposition: attachment; filename="'.basename($file_path).'"');
  52. header("Content-Transfer-Encoding: binary");
  53. header('Expires: 0');
  54. header('Pragma: no-cache');
  55.  
  56. ob_clean();
  57. flush();
  58. // Envia o arquivo para o cliente
  59. readfile($file_name);
  60. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement