Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ściąganie pliku w tle
rad11
post
Post #1





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Czy jest jakis sposob aby sciagac plik w tle tak aby mozna bylo wykonywac operacje na stronie? Plik moze sie generowac nawet 20 minut tak wiec potrzebuje uruchomic to w tle tak aby mozna bylo dalej dzialac na serwerze.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
rad11
post
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Zrobilem cos takiego:

  1. <?
  2. $userId = $_COOKIE['aausr'];
  3. $data = db_get("SELECT * FROM search.file_processes WHERE user_id = $userId ORDER by id DESC");
  4. ?>
  5.  
  6. <div id="processes" class="processes" style="position: absolute; top: 320px; right: 0; float:right; max-width: 270px; color: #5f5f5f; padding: 10px; text-align: left; border: 1px solid #cacaca; border-shadow: 0 2px 4px rgba(0, 0, 0, 0.15)">
  7.  
  8. <table class='table'>
  9. <thead>
  10. <tr>
  11. <th>ID</th>
  12. <th>Name</th>
  13. <th>Status</th>
  14. <th>Utworzono</th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <?
  19. foreach($data as $index => $value):
  20.  
  21. $status = ($value['status'] == 1)? 'Gotowe do pobrania.' : 'Trwa pobieranie' ;
  22.  
  23. ?><tr data-id="<? echo $value['id']; ?>"><td><? echo $value['id']; ?></td><td><a href="<? echo '/uploads/'.$value['file_name']; ?>" download><? echo $value['file_name']; ?></a></td><td><? echo $status; ?></td><td><? echo date('Y-m-d H:i:s', $value['created_at']); ?></td><tr><?
  24.  
  25. endforeach;
  26. ?>
  27. </tbody>
  28. </table>
  29. </div>
  30. <link href='//cdn.datatables.net/1.10.7/css/jquery.dataTables.css' type='text/css' rel='stylesheet'/>
  31. <script src='//cdn.datatables.net/1.3.0/js/jquery.dataTables.min.js' type='text/javascript'></script>
  32. <script>
  33. $(document).ready(function () {
  34. $('.table').dataTable({
  35. "sPaginationType": "full_numbers"
  36. });
  37. });
  38. </script>


  1. var processId = 0;
  2. $(document).ready(function () {
  3. $('.xls').click(function (e) {
  4. e.preventDefault();
  5. processId++;
  6. var url = $(this).attr('data-href');
  7. $.ajax({
  8. method: "GET",
  9. url: '?ajax=8',
  10. dataType: "JSON",
  11. data: {
  12. processId: processId
  13. },
  14. beforeSend: function () {
  15. $('.table tbody').prepend('<tr class="inprocess" data-id=' + processId + ' daata-inprocess="true"><td></td><td></td><td>Tworzenie pliku...</td><td></td></tr>');
  16. },
  17. success: function (res) {
  18. var res = JSON.parse(res);
  19. $('.table tbody tr').find('[data-id=' + res.processId + ']').prevObject[res.processId - 1].outerHTML = '<tr data-id=' + res.id + '><td>' + res.id + '</td><td><a href=' + res.file_url + '>' + res.file_name + '</a></td><td>Gotowe do pobrania.</td><td>' + res.time + '</td></tr>';
  20. }
  21. });
  22. });
  23. });


  1. <?php
  2. include 'PHPExcel.php';
  3. include 'PHPExcel/Writer/Excel5.php';
  4.  
  5.  
  6. function response() {
  7. $data = db_get("SELECT * FROM `search`.file_processes");
  8. $userId = $_COOKIE['aausr'];
  9. $file_name = uniqid() . '.xls';
  10. $time = time();
  11. $sql = 'INSERT INTO search.file_processes (file_url, file_path, status, file_name,user_id, created_at) VALUES ("' . (PAA_ROOT_DIR . "uploads/$file_name") . '", "' . (PAA_ROOT_DIR . "uploads/$file_name") . '", "' . (0) . '", "' . $file_name . '","' . $userId . '", "' . $time . '")';
  12.  
  13. if (!db_query($sql)) {
  14. die();
  15. }
  16. $lastId = mysql_insert_id();
  17. $objPHPExcel = new PHPExcel();
  18. $objPHPExcel->setActiveSheetIndex(0);
  19.  
  20. $row = 1;
  21. for ($index = 0; $index < 10000; $index++) {
  22. $objPHPExcel->getActiveSheet()->setCellValue('A' . $row, rand(0, 7000000));
  23. $objPHPExcel->getActiveSheet()->setCellValue('B' . $row, rand(0, 7000000));
  24. $objPHPExcel->getActiveSheet()->setCellValue('C' . $row, rand(0, 7000000));
  25. $row++;
  26. }
  27. $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
  28. $objWriter->save(PAA_ROOT_DIR . "uploads/$file_name");
  29.  
  30. if (file_exists(PAA_ROOT_DIR . "uploads/$file_name") == TRUE) {
  31. $sql = 'UPDATE search.file_processes SET status = 1 WHERE id = ' . $lastId;
  32. db_query($sql);
  33. echo json_encode(array('processId' => $_GET['processId'], 'id' => $lastId, 'file_name' => $file_name, 'file_url' => ("/uploads/$file_name"), 'time' => date('Y-m-d H:i:s', $time)));
  34. die();
  35. }
  36. }
  37.  
  38. response();
  39.  


Ale ten kod i tak powoduje ze nie mozna nic zrobic podczas sciagania pliku jakies pomysly co moze byc?

Ten post edytował rad11 5.08.2015, 11:42:46
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 19:31