Menu

[bugfix] File upload fails

Help
tobo
2010-06-16
2013-05-30
  • tobo

    tobo - 2010-06-16

    Hi everyone,

    I encountered a problem with posting files to some web server. After uploading a file the server claims that no file was uploaded.

    It took me about 6 hours to convince myself that there was no error in my code and reviewing the snoopy source, but finally I found the "bug" (I think it's a bug within the web server and not in the snoopy class, but I didn't look up rfc 1867 that deep).

    When uploading a file with a browser like firefox oder ie there is a header of the following format:

    Content-Type: multipart/form-data; boundary="-----------fsj83fksdfjk1d"
    

    This boundary is generated by the browser and separates the form file(s) and every other form data.

    But: Some web server (couldn't figure out what kind of server they are using; apache server work fine without this modification) need a (few) leading hyphen to accept the boundary.

    What I did to fix it:
    Edit snoopy source, look up in the function _prepare_post_body(), go to the line where

    $this->_mime_boundary = "----Snoopy".md5(uniqid(microtime()));
    

    Just add four hyphen "-" and save it.
    My snoopy.class.php now contains

    $this->_mime_boundary = "----Snoopy".md5(uniqid(microtime()));
    

    and everything works fine for me.

    Maybe some of the devs get accross this and fix this in the source.

    Cheers,
    tobo

     
  • tobo

    tobo - 2010-06-16

    Sorry, the original code contains

    $this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
    

    and i changed this to

    $this->_mime_boundary = "----Snoopy".md5(uniqid(microtime()));
    

    Cheers,
    tobo

     

Log in to post a comment.