How do i check if file is a divx file using php *Possibly Curl*

Discussion in 'PHP' started by rudeturk, Aug 29, 2008.

  1. #1
    Hello everyone,
    I need to check if a file is divx format using php, most definaty using curl.
    i did make a function before to check file format just from the extension but i cannot trust that.
    is there anyway to check if a file is divx format using php without wasting many bandwidth if so please help me out here.
     
    rudeturk, Aug 29, 2008 IP
  2. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #2
    ForumJoiner, Aug 29, 2008 IP
  3. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #3
    sorry i didnt understand it how does it work
     
    rudeturk, Aug 30, 2008 IP
  4. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Hey! Can you please send me any 1 file in divx format, and I will try to help you out into this problem. If the headers are formatted properly, we should be able to make out from them.

    Thanks

    imphp
     
    imphpguru, Aug 30, 2008 IP
  5. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #5
    rudeturk, Aug 30, 2008 IP
  6. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #6
    i dont want to look like im bumping a thread but i have been waiting for 2 days for help and this is what i get :(
     
    rudeturk, Aug 31, 2008 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Patience is a virtue...
     
    JAY6390, Aug 31, 2008 IP
  8. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #8
    You didnt need to tell me that, patience does not work when the topic is 3 pages down
     
    rudeturk, Aug 31, 2008 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You could have done some research into this. it's not hard. First thing you need to do is find out where in an avi header the divx code is stored...a quick google tells us its called a FOURCC code and that it is found in the format vidsXXXX where XXXX is the code :rolleyes: it's not rocket science from there to figure out how to use that information i hope
     
    JAY6390, Aug 31, 2008 IP
  10. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #10
    I have done alot of research into this, if i check the video headers all i get is Content-Type: video/x-msvideo
    and i checked the file formats, however i think x msvideo is used in other formats? i searched into that and couldnt find an answer i came here so someone could help i dont understand what your saying about fourcc code
     
    rudeturk, Aug 31, 2008 IP
  11. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Read in the first 1000 characters say of the actual video. In there there will be 8 characters that correspond to vidsDIVX for a divx video. The file that you gave above has vidsDIVX in the first 128 bytes

    [​IMG]
     
    JAY6390, Aug 31, 2008 IP
  12. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #12
    how do i do that without reading the whole file? thanks for info btw
     
    rudeturk, Aug 31, 2008 IP
  13. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Can you post your current CURL code?
     
    JAY6390, Aug 31, 2008 IP
  14. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #14
    this is a part of what i used to create something else but i was thinking it might help with this one:
    curl_setopt($emre, CURLOPT_HEADER, 1); // get the header
    curl_setopt($emre, CURLOPT_NOBODY, 1); // and *only* get the header
    curl_setopt($emre, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($emre, CURLOPT_TIMEOUT, 20);
    curl_setopt($emre, CURLOPT_URL, $divxfile);  
    PHP:
     
    rudeturk, Aug 31, 2008 IP
  15. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Well this code works fine...
    $f = fopen('http://www.jhepple.com/support/SampleMovies/AVI_DivX.avi','r') or die('UNABLE TO OPEN STREAM');
    $contents = fgets($f,1024);
    $pattern = '/vids(\w{4})/';
    preg_match($pattern,$contents,$found);
    echo $found[1];
    PHP:
    Obviously you will need to tweak it somewhat for whatever you need, but you see the basics of what it is meant to do
     
    JAY6390, Aug 31, 2008 IP
    rudeturk likes this.
  16. rudeturk

    rudeturk Well-Known Member

    Messages:
    884
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    120
    #16
    Thanks alot! rep added!
     
    rudeturk, Aug 31, 2008 IP
  17. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #17
    no problem
     
    JAY6390, Aug 31, 2008 IP