Results 1 to 3 of 3

Thread: system() function

  1. #1
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default system() function

    okay, a little background info:

    I'm trying to validate the mime type of a file (I want only images) uploaded to a server running PHP 5.2.11 (no mime_content_type() or finfo_open(FILEINFO_MIME_TYPE) support), and I ran across this method of using the system() function to return the mime type:
    PHP Code:
    system("file -bi 'filename.jpg'"); 
    and it works great. However, even when I assign it to a variable (e.g., $mimeType = system("file -bi 'filename.jpg'");), the result is automatically output to the browser. So, if I write a script like so:
    PHP Code:
    $mimeType system("file -bi 'filename.jpg'");
    if(
    preg_match('/image/'$mimeType)){ echo 'filename.jpg is an image file'; }
    else{ echo 
    'WARNING: filename.jpg is NOT an image file'; } 
    the browser displays:
    Code:
    image/jpegfilename.jpg is an image file
    .
    .
    ...Well, I guess that's more than "a little" background info.

    But does anyone have an idea of how to hide the output from system() from being displayed?

    Is there a better way to check the mime type (WITHOUT mime_content_type() or finfo_open())?

    thanks, everyone.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Use exec instead of system. By doing this, it will get rid of the output of system to the browser. As far as a better way to check mime type, no clue off the top of my head.

    Hope this helps nonetheless.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    traq (11-08-2009)

  4. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    well, that works, so good enough unless someone else has a better idea. thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •