Page 1 of 1

Storing file_get_contents("php://input") to mySQL MEDIUMBLOB

Posted: Fri Jan 08, 2010 5:58 am
by e2easy
I'm having problems storing the data I obtain from file_get_contents("php://input") into a mySQL MEDIUMBLOB. It ends up as null in the database.

This is the sort of thing I'm doing:-

Code: Select all

 
mysql_query("CREATE TABLE ALLFILES (
    author TINYTEXT,
    username VARCHAR(16),
    project TINYTEXT,
    treeFilename TINYTEXT,
    theData MEDIUMBLOB NOT NULL,
    comment TINYTEXT,
 
    treeAddress TINYTEXT DEFAULT '',
    indent INT DEFAULT 0,
    parentID INT DEFAULT -1,
    children INT DEFAULT 0,
 
    userIP TINYTEXT,
    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
 
    fileID INT NOT NULL AUTO_INCREMENT,
 
    PRIMARY KEY (fileID)
)");
 
#set up $author, $username, etc....
$theData=mysql_real_escape_string(file_get_contents("php://input"));
 
mysql_query("INSERT INTO ALLFILES
    (author,username,project,treeFilename,theData,comment,userIP)
    VALUES ('$author','$username','$project','$treeFilename','$theData','$comment','$userIP')
;") or die("error query 02");
 
 
I know that file_get_contents("php://input"); has the data. I tried the following test code which worked as expected...

Code: Select all

 
$fp = fopen("files/".$_GET["treeFilename"], "wb" );
fwrite( $fp, file_get_contents("php://input") );
fclose( $fp );
 
I've also tried $HTTP_RAW_POST_DATA , $GLOBALS[ 'HTTP_RAW_POST_DATA' ] , omitting the mysql_real_escape_string(), and trying addslashes(),.... nothing works. I always get null in the database.

How do I do this?

Re: Storing file_get_contents("php://input") to mySQL MEDIUMBLOB

Posted: Fri Jan 08, 2010 3:11 pm
by pickle
Echo the query - if it looks ok, try running it manually from the command line or phpmyadmin.