Код: Выделить всё
$(document).ready(function(){
$('#upload_csv').on("submit",function(e){
e.preventDefault();
$.ajax({
url:"import",
method:"POST",
data:new FormData(this),
contentType:false,
cache:false,
processData:false,
success: function(data){
if(data=='Error1')
{
alert("Invalid File");
}
else if(data == "Error2")
{
alert("Please Select File");
}
else
{
$('#success').html(data);
}
}
})
});
});
Код: Выделить всё
public function import()
{
if(!empty($_FILES["files"]["name"]))
{
$output = '';
$allowed_ext = array("csv");
$tmp = explode(".", $_FILES["files"]["name"]);
$extension = end($tmp);
if(in_array($extension, $allowed_ext))
{
$file_data = fopen($_FILES["files"]["tmp_name"], 'r');
print_r(fgetcsv($file_data));
}
else
{
echo 'Error1';
}
}
else
{
echo "Error2";
}
}
Код: Выделить всё
Array ( [0] => Id [1] => first_name [2] => last_name [3] => phone [4] => email )
Подробнее здесь: https://stackoverflow.com/questions/541 ... query-ajax
Мобильная версия