Próbuje stworzyć menadżer pobierania na mój serwer NAS który śmigałby w PHP+Jquery, i mam jeden bardzo poważny problem.
Mianowicie chciałbym aby serwer pobierał podane pliki w podanych godzinach do wybranego katalogu, oraz pokazywał stan pobierania.
Znalazłem skrypt który umożliwia pobieranie pliku z pokazywaniem stanu, lecz gdy odświeżę stronę skrypt przestaje pobierać plik, chciałbym aby skrypt działał w tle nawet w trakcie wyłączenia strony.
Domyślam się że możliwe jest to używając nodejs którego nie znam, lecz chciałbym poszukać innego rozwiązania, i tutaj pojawia się pytanie, czy da się takie coś zrobić w jQuery i PHP?
Oto skrypt który znalazłem, o ile to coś pomoże:
<?php /* * Remote File Copy PHP Script 2.0.0 * * Copyright 2012, Sebastian Tschan * <a href="https://blueimp.net" target="_blank">https://blueimp.net</a> * * Licensed under the MIT license: * <a href="http://www.opensource.org/licenses/MIT" target="_blank">http://www.opensource.org/licenses/MIT</a> */ $upload_dir = __DIR__."/downloads"; ?><!DOCTYPE HTML> <html lang="en"> <head> <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--> <meta charset="utf-8"> <title>Remote File Copy</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form> <input type="url" placeholder="URL" required> <button type="submit">Start</button> </form> <ul></ul> <progress value="0" max="100" style="display:none;"></progress> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> function callback(message) { if (!message) { console.error('Empty event callback response.'); return; } $.each(message, function (key, value) { switch (key) { case 'send': $('progress').show(); break; case 'progress': if (value && value.total) { $('progress').val(value.loaded / value.total * 100); } break; case 'done': $('<li style="color:green;">').text(value && value.name).appendTo('ul'); $('progress').hide(); break; case 'fail': $('<li style="color:red;">').text(value && value.message).appendTo('ul'); $('progress').hide(); break; } }); } $('form').on('submit', function (e) { e.preventDefault(); $('<iframe src="java script:false;" style="display:none;"></iframe>') .prop('src', '?url=' + encodeURIComponent($(this).find('input').val())) .appendTo(document.body); }); </script> </body> </html><?php exit; } $url = !empty($_REQUEST["url"]) && preg_match("|^http(s)?://.+$|", stripslashes($_REQUEST["url"])) ? $_REQUEST["callback"] : "callback"; $fileinfo = new stdClass(); // 1KB of initial data, required by Webkit browsers: function event_callback ($message) { } function get_file_path () { } function stream_notification_callback ($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { switch($notification_code) { case STREAM_NOTIFY_FILE_SIZE_IS: $fileinfo->size = $bytes_max; break; case STREAM_NOTIFY_MIME_TYPE_IS: $fileinfo->type = $message; break; case STREAM_NOTIFY_PROGRESS: if (!$bytes_transferred) { } break; } } function curl_progress_callback ($curl_resource, $total, $loaded) { if (!$loaded) { $fileinfo->size = $total; } } } if (!$url) { $success = false; } else if ($use_curl) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOPROGRESS, false ); curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, "curl_progress_callback"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FILE, $fp); $success = curl_exec($ch); $curl_info = curl_getinfo($ch); if (!$success) { } curl_close($ch); $fileinfo->size = $curl_info["size_download"]; $fileinfo->type = $curl_info["content_type"]; } else { if (!$success) { $err = error_get_last(); } } if ($success) { } if ($success) { } else { if (!$err) { } }?>