Notice: Undefined offset: 1 in C:\*********\Contact_Vcard_Parse.php on line 211
antonyf opened this issue · 1 comments
antonyf commented
Hi.
I used this script, it works perfectly in the demo provided, but when i moved the files into my libraries folder, and then use it with a custom form input, i get the following error:
Notice: Undefined offset: 1 in C:******\libraries\Contact_Vcard_Parse.php on line 211
I'm using JQuery ajax to post the form and file like so:
var formData = new FormData();
formData.append('file', t[0].files[0]);
formData.append('func', 'convert');
formData.append('uid', uuid);
formData.append('token', token);
formData.append('_accesscode', '');
formData.append('_mailonly', '');
formData.append('_phoneonly', '');
$.ajax({
url: 'http://locahost/website/index.php',
type: 'POST',
data : formData,
// dataType:'json',
contentType:false,
cache:false,
processData:false,
success : function(data) {
console.log(data);
return;
},
error: function(err){
serverError();
return;
}
})
my php is the like so :
!empty($_POST['_mailonly']), 'phoneonly' => !empty($_POST['_phoneonly']), 'accesscode' => preg_replace('/[^1-9]/', '', $_POST['_accesscode']), )); $fileError = $_FILES['file']['error']; if ( $fileError != UPLOAD_ERR_OK ) { $out['res'] = encodeS( 1 ); echo json_encode( $out); return; } if ( $_FILES['file']['name'] != '' ) { $file_array = explode( ".", $_FILES['file']['name'] ); $extension = end( $file_array ); if ( strtolower($extension) == 'vcf' ) { if ( $conv->fromFile( $_FILES['file']['tmp_name'] ) ) { $temp_data = $conv->toCSV(); if(!temp_data){ $out['res'] = encodeS( 8 ); echo json_encode( $out ); return; } } else { $out['res'] = encodeS( 0 ); echo json_encode( $out ); return; } } else { $out['res'] = encodeS( 5 ); //not supported file echo json_encode( $out ); return; } } else { $out['res'] = encodeS( 4 ); //no file uploaded echo json_encode( $out ); return; } $out['res'] = encodeS( 6 ); // success $out['arr'] = $temp_data; echo json_encode( $out ); return; ?>Any ideas??
antonyf commented
require_once('vcard_convert.php'); require_once('utils.php'); $conv = new vcard_convert(array( 'mailonly' => !empty($_POST['_mailonly']), 'phoneonly' => !empty($_POST['_phoneonly']), 'accesscode' => preg_replace('/[^1-9]/', '', $_POST['_accesscode']), )); $fileError = $_FILES['_vcards']['error']; if ( $fileError != UPLOAD_ERR_OK ) { $out['res'] = encodeS( 1 ); echo json_encode( $out ); return; } if ( !empty($_FILES['_vcards']['name']) ) { $file_array = explode( ".", $_FILES['_vcards']['name'] ); $extension = end( $file_array ); if ( strtolower($extension) == 'vcf' ) { if ( $conv->fromFile( $_FILES['_vcards']['tmp_name'] ) ) { $temp_data = $conv->toCSV(); // i changed to print function to a return function as a test.. it works in the demo but not in my files if(!temp_data){ $out['res'] = encodeS( 8 ); echo json_encode( $out ); return; } } else { $out['res'] = encodeS( 0 ); echo json_encode( $out ); return; } } else { $out['res'] = encodeS( 5 ); //not supported file echo json_encode( $out ); return; } } else { $out['res'] = encodeS( 4 ); //no file uploaded echo json_encode( $out ); return; } $out['res'] = encodeS( 6 ); $out['arr'] = $temp_data; echo json_encode( $out ); return;