Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. //login credentials
  2. $ftp_server = 'URL';
  3. $ftp_file_location = 'FILSTRUKTUR';
  4. $ftp_file = 'VÄGTILLFIL' . $time . '_' . $date . '.xml';
  5. $user = 'user';
  6. $password = 'password';
  7.  
  8. //local file
  9. $local_file = WP_PLUGIN_DIR . 'VÄGTILLLOKALFIL';
  10. //open and write to local file
  11. $file_to_write_to = fopen( $local_file, 'w' );
  12. //connect
  13. if ( $conn_id = ftp_connect( $ftp_server ) ) {
  14. //login
  15. if ( $login_result = ftp_login( $conn_id, $user, $password ) ) {
  16. //get array of existing filenames on server
  17. $files_on_server = ftp_nlist( $conn_id, $ftp_file_location );
  18. //check if todays file exists on server, if connect otherwise do nothing
  19. if ( in_array( $ftp_file, $files_on_server ) ) {
  20.  
  21. //get the server file and write to local file
  22. if ( ftp_fget( $conn_id, $file_to_write_to, $ftp_file, FTP_ASCII, 0 ) ) {
  23.  
  24. $file_to_read = fopen( $ftp_file, 'r' ); -> detta blir sökvägen bara, failed to open stream.
  25.  
  26. $count_lines = 0;
  27.  
  28. while ( ( $line = fgets( $file_to_read ) ) !== false ) {
  29. //convert
  30. $converted_row = html_entity_decode( $line );
  31. //append to local file
  32. fwrite( $converted_row, $file_to_write_to );
  33.  
  34. if ($count_lines++ == 100) {
  35. break;
  36. }
  37. }
  38.  
  39. fclose( $file_to_read );
  40. // htmlspecialchars($str);
  41.  
  42. $xmlReader = new XMLReader;
  43. $xmlReader->open( $file_to_write_to );
  44. $doc = new DOMDocument;
  45.  
  46. längre ner stängs de andra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement