vs6262
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору ManHunter спасибо. сейчас работает. Sutar я там добавил *URIComponent() index.html Код: <!DOCTYPE HTML> <html> <body> <head> <meta charset="utf-8"> </head> <form name="upload"> <input id="fileInput" type="file" name="myfile"> <input type="submit" value="Загрузить"> </form> <div id="log">Прогресс загрузки</div> <script> var fname=""; document.getElementById('fileInput').onchange = function () { // alert('Selected file: ' + this.value); fname = encodeURIComponent(this.value); }; function log(html) { document.getElementById('log').innerHTML = html; } function onSuccess() { log('success'); } function onError() { log('error'); } function onProgress(loaded, total) { log(loaded + ' / ' + total); } document.forms.upload.onsubmit = function() { var file = this.elements.myfile.files[0]; if (file) { upload(file); } return false; } function upload(file) { var xhr = new XMLHttpRequest(); // обработчики можно объединить в один, // если status == 200, то это успех, иначе ошибка xhr.onload = xhr.onerror = function() { if (this.status == 200) { log("success"); } else { log("error " + this.status); } }; // обработчик для закачки xhr.upload.onprogress = function(event) { log(event.loaded + ' / ' + event.total); } xhr.open("POST", "upload.php?fname="+fname, true); xhr.send(file); } </script> </body> </html> | upload.php Код: <?php function decodeURIComponent($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'UTF-8');; } $input=fopen('php://input', 'rb'); $f=fopen(decodeURIComponent($_GET['fname']), 'w+'); while(!feof($input)) { $data=fread($input,100000); fwrite($f,$data); unset($data); } fclose($input); ?> | |