in reply to Re^2: Answer: How do I find the type of an image?
in thread How do I find the type of an image?

* you can even name it my.jpg & it will execute your perl script

..... yes, the basic linux filesystem has file permissions..... not file extensions... to determine if a file is an executable..... this is far safer than extensions as you are beginning to find out..... you probably are coming from a MSWindow's background and need to learn more about the improved security of linux....

it probably is getting crazy for you, if you are running a dual boot with linux and windows..... then you will start seeing files from the Windows OS, that seem marked executable, or vice versa... or you do alot of double-clicking on icons and expect the system to do what you want".. :-)

.... the way it works on linux is:

....you instruct your shell to execute a program, and regardless of it's name it will see if its marked as executable by you or your group..... if it is...it tries to execute it.... but if you try to execute a jpg or bmp.... it won't run....and will just return an error...... and then there are the shebang lines :-)....... maybe read linux programming... and the Rute User's Guide

...that brings us to default programs and apps which will properly load your file....its a part of your system setup....ubuntu uses the Gnome Desktop to determine file types thru a MIME-information setup..... first look for extension....then check type with a file-like command

...this is all getting to the point of you needing to read up on linux....it isn't a Perl problem

...see monitor suid and world writtable files for an example of checking perms.....

....also on ubuntu....try installing the program Midnight Commander, go thru it's menus and see what info is tracked on files

I have many images saved without extensions ... and it works that way.

...sure it does..... but that is because the Ubuntu Desktop handles it all for you..... as a matter of fact, your only problem may be that you have a destop setting set to hide file extensions, like they do on Winblows

why don't you right-click on those images and get the info?...... are you trying to automatically rename something like the browser's cache of images? :-) which are named like numbers?

..... you need to learn how Desktops work...... it's actually a program that has MIME type records built in..... go see MIME modules for Perl


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku
  • Comment on Re^3: Answer: How do I find the type of an image?

Replies are listed 'Best First'.
Re^4: Answer: How do I find the type of an image?
by Anonymous Monk on Dec 29, 2009 at 13:23 UTC
    ...dude your....style of..........writing is..............really fscking annoying................there are.....other,,,,,punctuation:::::::marks!!!!!!in the;;;;;;english language--------and/they~can"be"used(one)at{a}time'you((((((((know???????Also are+++++++you really''''''''so broke you)))))))can''''t afford to```````repair########your Shift key??????
      ..yeah... the style is called stream of conciousness.... it's brought on by the Text'ing craze.... where you don't want to waste time punctuating just to convey a few thought nuggets

      ....people who properly punctuate will soon be obsolete as the Text'ers take over the world


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku
        well it...makes...you look....like a....moron who~se....desperately trying....to appear....c00l
Re^4: Answer: How do I find the type of an image?
by ahmad (Hermit) on Dec 29, 2009 at 14:42 UTC

    I don't know what you are trying to accomplish with this kind of answers

    Your previous replay was:

    that is not true..... .htm, .html, .jpg,. gif,.bmp,.png,...etc..extensions...etc....are all very important in the linux file system

    And now you are saying that extensions are not important, and what's important is the file permission (The same idea I have explained in my replay just right before yours)

    ...sure it does..... but that is because the Ubuntu Desktop handles it all for you..... as a matter of fact, your only problem may be that you have a destop setting set to hide file extensions, like they do on Winblows

    As I wrote those images uses no extensions I have deleted the extensions myself, so I am not confused with anything as you think.

    And finally I have no problem with anything as you thought, I am just providing a code that might benefit someone else.

    As *some* people uses file extension to determine the file type which I do not consider as a good practice.

    About the permission thing: Just because you *think* your files are safe it does not mean it is, consider a web server (Apache for example) that is running scripts without suexec enabled , everybody on that server will have to grant group permission to the web server in order to let it execute those scripts.

    That's just one of many examples, just keep in mind that we're humans and we're prone to mistakes & you should always expect the worst thing to happen.

    Finally, by adding few more checking to your code ... You are not only protecting yourself from being cracked, You are protecting other users on the shared environment you are working on. And possibly the entire server from being rooted.

    Finally I am not here to discuss Linux configurations & security issues. And I will skip answering any more replays to this node.

    BTW, Thanks for the MIME types url you posted as again you proved my point, take a look yourself

      And I will skip answering any more replays to this node.

      ...thats ok,... i will just finish by saying on a properly configured linux system, it's not a problem..... all that will happen is that errors will be thrown if someone tries a file masquerade.

      Every linux distro i've seen, always puts files into your filesystem with a 0644 permission, and you need to chmod it to get it to even get it attempted to be executed by the kernel

      And if someone tries to slip a malicious binary into a file named as an image, only errors will be thrown when your Desktop(or whatever) tries to open it.....you will get "wrong header or not a correct filetype" errors

      Of course, that does not prevent people from shooting themselves in the foot..... anyone can get a malicious file , chmod it +e, and execute it..... thats why they train people to use computers, to avoid those obvious errors ..... the only protection from those idiots is to give them their own sandbox... called a home directory.

      And always compile your own from source code.... don't trust RPM's or canned pre-compiled code, unless you have no choice


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku