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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
e2easy
Forum Newbie
Posts: 1
Joined: Fri Jan 08, 2010 5:42 am

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

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

Echo the query - if it looks ok, try running it manually from the command line or phpmyadmin.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply