ascii or binary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • greg

    ascii or binary

    Hello,

    I'm searching to know if a local file is ascii or binary.
    I couldn't find it in the manual, is there a way to know that ?

    thanks,

    --
    greg


  • frizzle

    #2
    Re: ascii or binary


    greg wrote:[color=blue]
    > Hello,
    >
    > I'm searching to know if a local file is ascii or binary.
    > I couldn't find it in the manual, is there a way to know that ?
    >
    > thanks,
    >
    > --
    > greg[/color]

    AFAIK it depends on what kind of file it is. Not sure, but ascii are
    txt, csv, html etc, binary are images, mp3's etc.
    Correct me if i'm wrong.

    Comment

    • ZeldorBlat

      #3
      Re: ascii or binary


      greg wrote:[color=blue]
      > Hello,
      >
      > I'm searching to know if a local file is ascii or binary.
      > I couldn't find it in the manual, is there a way to know that ?
      >
      > thanks,
      >
      > --
      > greg[/color]

      <http://www.php.net/mb_detect_encod ing>

      Comment

      • greg

        #4
        Re: ascii or binary

        >[color=blue]
        > <http://www.php.net/mb_detect_encod ing>
        >[/color]
        excuse my ignorance, but do you mean that if this function returns "ascii",
        it's ascii ... if not it's binary ?
        I'm not really sure to get your tip.

        --
        greg


        Comment

        • greg

          #5
          Re: ascii or binary

          [color=blue]
          > AFAIK it depends on what kind of file it is. Not sure, but ascii are
          > txt, csv, html etc, binary are images, mp3's etc.
          > Correct me if i'm wrong.
          >[/color]

          surely, but this means I must think of all the possible file extension
          decide whether it's ascii or binary.
          it seems to be limited, but thx anyway.

          --
          greg


          Comment

          • Bent Stigsen

            #6
            Re: ascii or binary

            greg wrote:[color=blue][color=green]
            >>AFAIK it depends on what kind of file it is. Not sure, but ascii are
            >>txt, csv, html etc, binary are images, mp3's etc.
            >>Correct me if i'm wrong.
            >>[/color]
            >
            > surely, but this means I must think of all the possible file extension
            > decide whether it's ascii or binary.
            > it seems to be limited, but thx anyway.[/color]

            In a sense he is right, it is not really straightforward to make the
            distinction, if you strictly mean the ascii character set.

            Binary just means that it consists of binary patterns or sequence of
            bits, varied in length and meaning. The content of a binary file only
            makes sense to an application which knows what the sequence of bits
            means. When a file is viewed in a text-editor, then the data is
            (possibly mistakenly) chopped up in 8-bits (or whatever), and the
            corresponding symbol of that value is displayed, which may or may not
            make any sense at all. Strictly speaking, the only difference between
            ascii and non-ascii would be whether or not each chunk of bits is
            *intended* to correspond to a specific symbol in the Ascii character
            table.

            If you by ascii generally mean plain readable/printable text, not
            necessarilly limited to ascii, then there is tools that could help you.




            If you are on a linux/unix, check:


            You could just ignore the subtype, and only distinguish on mediatype
            between text and everything else.

            /Bent

            Comment

            • greg

              #7
              Re: ascii or binary

              > In a sense he is right, it is not really straightforward to make the[color=blue]
              > distinction, if you strictly mean the ascii character set.
              >
              > Binary just means that it consists of binary patterns or sequence of bits,
              > varied in length and meaning. The content of a binary file only makes
              > sense to an application which knows what the sequence of bits means. When
              > a file is viewed in a text-editor, then the data is (possibly mistakenly)
              > chopped up in 8-bits (or whatever), and the corresponding symbol of that
              > value is displayed, which may or may not make any sense at all. Strictly
              > speaking, the only difference between ascii and non-ascii would be whether
              > or not each chunk of bits is *intended* to correspond to a specific symbol
              > in the Ascii character table.
              >
              > If you by ascii generally mean plain readable/printable text, not
              > necessarilly limited to ascii, then there is tools that could help you.
              >
              > http://dk2.php.net/mime_content_type
              > http://pecl.php.net/package/fileinfo
              >
              > If you are on a linux/unix, check:
              > http://www.freebsd.org/cgi/man.cgi?query=file
              >
              > You could just ignore the subtype, and only distinguish on mediatype
              > between text and everything else.
              >
              > /Bent[/color]

              Thank you for these explanations.
              In fact, I should have told why I want know make the difference between
              ascii and binary files.
              I have a list of files to send via FTP from a local machien to a remote
              server.
              the ftp_put function needs an argument that can be FTP_ASCII or FTP_BINARY.
              I don't know how to choose dynamicaly this argument as the must upload
              various file types.

              tia,

              --
              greg


              Comment

              • Kimmo Laine

                #8
                Re: ascii or binary

                "greg" <greg@no-spam.org> wrote in message
                news:44166b72$0 $7933$636a55ce@ news.free.fr...[color=blue][color=green]
                >> In a sense he is right, it is not really straightforward to make the
                >> distinction, if you strictly mean the ascii character set.
                >>
                >> Binary just means that it consists of binary patterns or sequence of
                >> bits, varied in length and meaning. The content of a binary file only
                >> makes sense to an application which knows what the sequence of bits
                >> means. When a file is viewed in a text-editor, then the data is (possibly
                >> mistakenly) chopped up in 8-bits (or whatever), and the corresponding
                >> symbol of that value is displayed, which may or may not make any sense at
                >> all. Strictly speaking, the only difference between ascii and non-ascii
                >> would be whether or not each chunk of bits is *intended* to correspond to
                >> a specific symbol in the Ascii character table.
                >>
                >> If you by ascii generally mean plain readable/printable text, not
                >> necessarilly limited to ascii, then there is tools that could help you.
                >>
                >> http://dk2.php.net/mime_content_type
                >> http://pecl.php.net/package/fileinfo
                >>
                >> If you are on a linux/unix, check:
                >> http://www.freebsd.org/cgi/man.cgi?query=file
                >>
                >> You could just ignore the subtype, and only distinguish on mediatype
                >> between text and everything else.
                >>
                >> /Bent[/color]
                >
                > Thank you for these explanations.
                > In fact, I should have told why I want know make the difference between
                > ascii and binary files.
                > I have a list of files to send via FTP from a local machien to a remote
                > server.
                > the ftp_put function needs an argument that can be FTP_ASCII or
                > FTP_BINARY.
                > I don't know how to choose dynamicaly this argument as the must upload
                > various file types.[/color]


                I suppose you could just send binary always.

                --
                "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
                spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)


                Comment

                • Bent Stigsen

                  #9
                  Re: ascii or binary

                  greg wrote:
                  [snip][color=blue]
                  > Thank you for these explanations.
                  > In fact, I should have told why I want know make the difference between
                  > ascii and binary files.
                  > I have a list of files to send via FTP from a local machien to a remote
                  > server.
                  > the ftp_put function needs an argument that can be FTP_ASCII or FTP_BINARY.
                  > I don't know how to choose dynamicaly this argument as the must upload
                  > various file types.[/color]

                  The only purpose of ascii transfer is to translate line-endings
                  (CR,LF,CRLF) between differing systems, but many text-editors can
                  handle any type, so always using binary as Kimmo suggest is a good
                  option, since this leaves files intact, whereas using ascii by mistake
                  could render a file useless.

                  Although I would think that to use ascii-transfer if and only if file
                  has an extension of ".txt" should be safe.

                  /Bent

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: ascii or binary

                    Kimmo Laine wrote:[color=blue]
                    > "greg" <greg@no-spam.org> wrote in message
                    > news:44166b72$0 $7933$636a55ce@ news.free.fr...
                    >[color=green][color=darkred]
                    >>>In a sense he is right, it is not really straightforward to make the
                    >>>distinctio n, if you strictly mean the ascii character set.
                    >>>
                    >>>Binary just means that it consists of binary patterns or sequence of
                    >>>bits, varied in length and meaning. The content of a binary file only
                    >>>makes sense to an application which knows what the sequence of bits
                    >>>means. When a file is viewed in a text-editor, then the data is (possibly
                    >>>mistakenly ) chopped up in 8-bits (or whatever), and the corresponding
                    >>>symbol of that value is displayed, which may or may not make any sense at
                    >>>all. Strictly speaking, the only difference between ascii and non-ascii
                    >>>would be whether or not each chunk of bits is *intended* to correspond to
                    >>>a specific symbol in the Ascii character table.
                    >>>
                    >>>If you by ascii generally mean plain readable/printable text, not
                    >>>necessaril ly limited to ascii, then there is tools that could help you.
                    >>>
                    >>>http://dk2.php.net/mime_content_type
                    >>>http://pecl.php.net/package/fileinfo
                    >>>
                    >>>If you are on a linux/unix, check:
                    >>>http://www.freebsd.org/cgi/man.cgi?query=file
                    >>>
                    >>>You could just ignore the subtype, and only distinguish on mediatype
                    >>>between text and everything else.
                    >>>
                    >>>/Bent[/color]
                    >>
                    >>Thank you for these explanations.
                    >>In fact, I should have told why I want know make the difference between
                    >>ascii and binary files.
                    >>I have a list of files to send via FTP from a local machien to a remote
                    >>server.
                    >>the ftp_put function needs an argument that can be FTP_ASCII or
                    >>FTP_BINARY.
                    >>I don't know how to choose dynamicaly this argument as the must upload
                    >>various file types.[/color]
                    >
                    >
                    >
                    > I suppose you could just send binary always.
                    >[/color]

                    No, that will screw up the file if you're going between different OS's
                    such as Windows and Unix. There's a reason why there are different
                    transfer modes!

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: ascii or binary

                      Bent Stigsen wrote:[color=blue]
                      > greg wrote:
                      > [snip]
                      >[color=green]
                      >> Thank you for these explanations.
                      >> In fact, I should have told why I want know make the difference
                      >> between ascii and binary files.
                      >> I have a list of files to send via FTP from a local machien to a
                      >> remote server.
                      >> the ftp_put function needs an argument that can be FTP_ASCII or
                      >> FTP_BINARY.
                      >> I don't know how to choose dynamicaly this argument as the must upload
                      >> various file types.[/color]
                      >
                      >
                      > The only purpose of ascii transfer is to translate line-endings
                      > (CR,LF,CRLF) between differing systems, but many text-editors can handle
                      > any type, so always using binary as Kimmo suggest is a good option,
                      > since this leaves files intact, whereas using ascii by mistake could
                      > render a file useless.
                      >
                      > Although I would think that to use ascii-transfer if and only if file
                      > has an extension of ".txt" should be safe.
                      >
                      > /Bent[/color]

                      Transferring a text file from Windows to Unix will cause problems in VIM
                      and many other Unix editors. And not all Windows editors support
                      Unix-style nl characters.

                      Better to determine if it's a text file, and only if unknown default to
                      binary.

                      Alternatively, scan the file for non-char values.


                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • greg

                        #12
                        Re: ascii or binary

                        >[color=blue]
                        > Transferring a text file from Windows to Unix will cause problems in VIM
                        > and many other Unix editors. And not all Windows editors support
                        > Unix-style nl characters.
                        >
                        > Better to determine if it's a text file, and only if unknown default to
                        > binary.
                        >
                        > Alternatively, scan the file for non-char values.
                        >
                        >[/color]

                        Ok, I'm gonna use this solution.
                        Thank you all for your help.

                        --
                        greg


                        Comment

                        • Bent Stigsen

                          #13
                          Re: ascii or binary

                          Jerry Stuckle wrote:[color=blue]
                          > Bent Stigsen wrote:[/color]
                          [snip][color=blue][color=green]
                          >> The only purpose of ascii transfer is to translate line-endings
                          >> (CR,LF,CRLF) between differing systems, but many text-editors can
                          >> handle any type, so always using binary as Kimmo suggest is a good
                          >> option, since this leaves files intact, whereas using ascii by mistake
                          >> could render a file useless.
                          >>
                          >> Although I would think that to use ascii-transfer if and only if file
                          >> has an extension of ".txt" should be safe.
                          >>
                          >> /Bent[/color]
                          >
                          > Transferring a text file from Windows to Unix will cause problems in VIM
                          > and many other Unix editors. And not all Windows editors support
                          > Unix-style nl characters.[/color]

                          Those bastards. Well, they just have to change. Other transfer
                          protocols or portable storage devices makes it impossible to control
                          anyway, so (using a bad analogy) insisting on proper conversion when
                          using ftp is like waving a hand to stop a hurricane.

                          If the destination is a web-folder or accessed in an alternative way
                          by different clients, it doesn't matter in the slightest, or in worst
                          case even a bad idea.
                          [color=blue]
                          > Better to determine if it's a text file, and only if unknown default to
                          > binary.[/color]

                          I understand that it was designed that way, so that things was neat
                          and tidy in both camps, but the battle of the line-endings is already
                          lost to chaos, nothing short of a revolution is going to change that.

                          /Bent

                          [snip]

                          Comment

                          • Erwin Moller

                            #14
                            Re: ascii or binary

                            ZeldorBlat wrote:
                            [color=blue]
                            >
                            > greg wrote:[color=green]
                            >> Hello,
                            >>
                            >> I'm searching to know if a local file is ascii or binary.
                            >> I couldn't find it in the manual, is there a way to know that ?
                            >>
                            >> thanks,
                            >>
                            >> --
                            >> greg[/color]
                            >
                            > <http://www.php.net/mb_detect_encod ing>[/color]

                            Hi,

                            You made me curious. :-)

                            How can that function diffentiate between encodings?
                            How is that done?

                            I mean: The string contains a set of numbers behind the scene that have a
                            certain corresponding character depending on the characterset used.

                            Now it looks the other way around: It's like the string also contains
                            information on what encoding is used for it.
                            It that true?

                            I must be missing something completely.

                            Can anybody explain how this function works?

                            TIA

                            Regards,
                            Erwin Moller

                            Comment

                            Working...