Page 1 of 1

PHP_FTP,windows,unix & line breaks (funtimes!)

Posted: Wed Mar 22, 2006 4:12 pm
by wh33t
Hey guys,

So here is my problem. I've written a nifty little script to ftp a bunch of files and directories to an ftp server of my choice. The only problem with it is that after I upload all of the files, the text files lose all of there line breaks and spacing. I have done some research and discovered that this is because the program that the text files were written on, (probably Dreamweaver) use the windows method of writing line breaks and not the unix method.

I have noticed that when I use FileZilla from my laptop this too also happens. Yet if i use Internet Explorer in FTP mode it does remove the line breaks after the upload.

So anyone got an idea about how to approach this? Should I make the programmer who wrote all these php scripts export them out of a dreamweaver in a specific format? Can i turn on some conversion option in php... I'm confused, any help would be appreciated. thank you.

Wh33t

Posted: Wed Mar 22, 2006 4:17 pm
by feyd
transfer the files in ascii mode?, that's usually the way to send anything text-file. Alternately, you can, knowning the type of file, load the file into memory rewriting the binary data to switch which bytes are used for line breaks.

Posted: Wed Mar 22, 2006 4:20 pm
by wh33t
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


It is already uploading the files in ascii format.

Code: Select all

//Upload all the files
  foreach($cms_files as $files_to_upload)
    {
    $local_file = str_replace($current_cms_root , "cms_current/", $files_to_upload);
    $remote_file = str_replace($current_cms_root , $current_cms_root_install, $files_to_upload);
    if(ftp_put($conn_id_install,$remote_file,$local_file,FTP_ASCII))
      {
      print 'File Uploaded ['.$remote_file.']<br>';
      } else {
      print 'Error uploading ['.$remote_file.']<br>';
      }
    }

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Mar 22, 2006 4:27 pm
by feyd
I haven't had this problem, so I guess you'll need to rewrite the file temporarily replacing the characters getting screwed up with ones that don't.