Использование jQuery Ajax File Upload plugin. Это сработало для меня!
function ajaxFileUpload()
{
//starting setting some animation when the ajax starts and completes
$("#loading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
/*
prepareing ajax file upload
url: the url of script file handling the uploaded files
fileElementId: the file type of input element id and it will be the index of $_FILES Array()
dataType: it support json, xml
secureuri:use secure protocol
success: call back function when the ajax complete
error: callback function when the ajax failed
*/
$.ajaxFileUpload
(
{
url:'doajaxfileupload.php',
secureuri:false,
fileElementId:'fileToUpload',
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}else
{
alert(data.msg);
}
}
},
error: function (data, status, e)
{
alert(e);
}
}
)
return false;
}
Благодарим за быстрый ответ !. Но как скрипт php может взять файл, который вы отправите ему, и преобразовать его в массив байтов и отправить через TCP-сокет? Соединитель Tcp принимает только буферизованную строку. –
Файл будет загружен на веб-сервер по вызову AJAX. В вашем PHP-коде вы можете извлечь файл из массива $ _FILES. $ _FILES ['fileToUpload'] будет более конкретным, так как имя элемента ввода html-файла было «fileToUpload». – papaiatis
Подробнее о массиве PHP $ _FILES и его использовании [нажмите здесь] (http://www.w3schools.com/php/php_file_upload.asp) – papaiatis