-2

Why this code is not working in Codeigniter, while when I remove base64_encode the code runs perfectly and the same if I use file_get_contents, why both function are not working?

$imagedata = mysql_real_escape_string(base64_encode(file_get_contents($_FILES["userfile"]["tmp_name"])));

Thanks in advance.

Mr.Web
  • 6,992
  • 8
  • 51
  • 86
Asher
  • 75
  • 6
  • 1
    What's your PHP version and what errors do you get? What happens if you do this: `var_dump($_FILES["userfile"]["tmp_name"])`? – Mr.Web Dec 31 '14 at 07:37
  • nothing error displayed just blank the page when i click the submit button and my php version is 5.5.11 – Asher Dec 31 '14 at 07:45

1 Answers1

-1

mysql_real_escape_string is making error here . These two link will help you to handle this link1 and link2

so please use $this->db->escape($val) instead of mysql_real_escape_string

 <?php
    // <= PHP 5
    $data = file_get_contents($_FILES["userfile"]["tmp_name"], true);
    // > PHP 5
    $data = file_get_contents($_FILES["userfile"]["tmp_name"], FILE_USE_INCLUDE_PATH);
    ?>

$_FILES["userfile"]["tmp_name"] produce file name like

<?php
// <= PHP 5
 $data = $this->db->escape(base64_encode(file_get_contents("test/faruk.txt", true)));
// > PHP 5
 $data = $this->db->escape(base64_encode(file_get_contents("test/faruk.txt", FILE_USE_INCLUDE_PATH)));
echo $data; 
?>

and my output is SGVsbG8gd29ybGQxNDEyMTYyMTYx for content "Hello world1412162161"

Community
  • 1
  • 1
Faruk Omar
  • 1,173
  • 2
  • 14
  • 22
  • i know this code is run perfectly but i want to include also base64_encode..i have a problem only in codeigniter,my code is run perfectly in core php – Asher Dec 31 '14 at 07:50
  • No it should not be. There is nothing of codeIgniter and no relation of codeIgniter here , mysql_real_escape_string is the issue here – Faruk Omar Dec 31 '14 at 08:13
  • dear i'm using in most of projects in core php and i remove mysql_real_escape_string to check the code but the problem is same, after submit the form page is blank..i don't know that relate to codeigniter or not but i getting problem in codeigniter so i ask..! – Asher Dec 31 '14 at 08:25
  • Please use $this->db->escape($val) instead of mysql_real_escape_string i am pretty sure it will help you – Faruk Omar Dec 31 '14 at 08:28
  • also have a same problem..i am using this code now $val = base64_encode(file_get_contents($_FILES['userfile']['tmp_name'])); $profile_img= $this->db->escape($val); – Asher Dec 31 '14 at 08:33
  • yup, and now i also find the problem,problem is that i am sending a form thorugh ajax so the problem is occur and here is the link to ajax that i use.. http://www.formget.com/ajax-image-upload-php/ – Asher Dec 31 '14 at 08:49
  • You no need to do such thing , you just change filed type to longblob in db and follow the link [here](http://pujanpiya.com.np/?q=node/25) – Faruk Omar Dec 31 '14 at 08:57