PHP reduced my variable string length

Hello Friends here, am having the issue of PHP reducing my string length. Here is the scenario.

am trying to upload image ajaxically using this jQuery plugin

$image = file_get_contents($_FILES[$name]['tmp_name']);
$q = "INSERT INTO topic_cp_value(topic_id, class_property_id, image) VALUES('$topic_id','$cp_id', '$image')";

The following is when I printed out the $q (SQL query) as can be seen that it’s incomplete, no closing single-quote, no close bracket. I just formatted my computer and have used Wamp server before without a problem, I thought of trying a new sever bundle called Uniform Server which work similarly like Wamp, except it got a few tools which are quite useful. But after migrating to that I have this problem, maybe it has to do with some PHP server configuration ?

INSERT INTO topic_cp_value(topic_id, class_property_id, image) VALUES('1','11', '\\xFF\\xD8\\xFF\\xE0\\uFFFD\\x10JFIF\\uFFFD\\x01\\x01\\x01\\uFFFD`\\uFFFD`\\uFFFD\\uFFFD\\xFF\\xDB\\uFFFDC\\uFFFD\\x02\\x01\\x01\\x02\\x01\\x01\\xA2\\u0160(\\uFFFD\\xA2\\u0160\\xF3\\xEF\\u2021\\xFF\\uFFFD\\xB5\\x17\\u201A\\xFE&\\x0F\\x16O\\xA5j\\xBB\\xF4\\u0178\\x06La\\xD4uybh\\xB4\\xCC\\xAAn\\x90\\xC7r\\xD8\\x8D\\xC2\\x0F\\xBCA\\xE3\\u0192\\xF7YX\\xEFK\\vZ\\xACe:qmF\\xD7imwe\\x7FW\\xA2\\xEEr\\xD7\\xC6\\xE1\\xE8\\xCE\\x14\\xEBMFS\\xBA\\u0160m&\\xEC\\xAE\\xED\\xDE\\xC9]\\u017E\\u0192E~z\\xFE\\xD3_\\xF0Z\\xC9\\xAC\\xF5\\xF9\\xB5\\xDC\\xE7\\xE3\\xBC\\xE2\\u0178\\x0E\\xF1.y\\u0153b\\xB4\\xC3j5(\\xC9\\xA5\\xA49\\xB9e\\x17e\\xD1\\xB5\\xD3\\xA4]\\xB6\\xB1\\xFA\\xE9\\\\\\x1F\\xC3=\\"\\" \\u017D\\xB6\\u

Any Help is appreciated, Thanks

p.s. I have cut off the length of those hexadecimal image character in the middle to make this thread shorter.

Try passing $image through mysql_real_escape_string() (if you use mysql).

Goodness :slight_smile:
It works :-))))) So happy :-))))

I was a bit afraid just now because this is for my university Final Year Project & I have to do the presentation in the next 2 or few following days. And suddenly this simple but very tricky bug comes up after formatting the computer…yeah, am using MySQL, so just realized that my PHP magic_quotes_gpc was not turned on the new server.

guido2004 - “From Italy with love”, you are like sending your love from Italy and now I like to send my :heart::heart::heart: too from Malaysia :-))))

Now I am beginning to find this quote makes sense :slight_smile:

“Love is the only flower that grows and blossoms Without the aid of the seasons.” - Kahlil Gibran , source at

And it shouldn’t be :slight_smile: