Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //login credentials
- $ftp_server = 'URL';
- $ftp_file_location = 'FILSTRUKTUR';
- $ftp_file = 'VÄGTILLFIL' . $time . '_' . $date . '.xml';
- $user = 'user';
- $password = 'password';
- //local file
- $local_file = WP_PLUGIN_DIR . 'VÄGTILLLOKALFIL';
- //open and write to local file
- $file_to_write_to = fopen( $local_file, 'w' );
- //connect
- if ( $conn_id = ftp_connect( $ftp_server ) ) {
- //login
- if ( $login_result = ftp_login( $conn_id, $user, $password ) ) {
- //get array of existing filenames on server
- $files_on_server = ftp_nlist( $conn_id, $ftp_file_location );
- //check if todays file exists on server, if connect otherwise do nothing
- if ( in_array( $ftp_file, $files_on_server ) ) {
- //get the server file and write to local file
- if ( ftp_fget( $conn_id, $file_to_write_to, $ftp_file, FTP_ASCII, 0 ) ) {
- $file_to_read = fopen( $ftp_file, 'r' ); -> detta blir sökvägen bara, failed to open stream.
- $count_lines = 0;
- while ( ( $line = fgets( $file_to_read ) ) !== false ) {
- //convert
- $converted_row = html_entity_decode( $line );
- //append to local file
- fwrite( $converted_row, $file_to_write_to );
- if ($count_lines++ == 100) {
- break;
- }
- }
- fclose( $file_to_read );
- // htmlspecialchars($str);
- $xmlReader = new XMLReader;
- $xmlReader->open( $file_to_write_to );
- $doc = new DOMDocument;
- längre ner stängs de andra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement