Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Undefined offset: 1 in C:\*********\Contact_Vcard_Parse.php on line 211 #21

Open
antonyf opened this issue Jun 4, 2021 · 1 comment

Comments

@antonyf
Copy link

antonyf commented Jun 4, 2021

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
Copy link
Author

antonyf commented Jun 4, 2021

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;



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant