468,490 Members | 2,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

store image blob in database joomla

1
Hello,
I'm developping a new joomla component, so i want to store pictures in database table in field type : blob. i'm wondery how to proceed to do this.

I'm using this to get file from the form :

$file = JRequest::getVar( 'img2', null, 'files', 'array' );
jimport('joomla.filesystem.file');
$filename = JFile::makeSafe($file['img2']);
$src = $file['tmp_name'];
$image = mysql_escape_string(file_get_contents($file['img2']['tmp_name']));
$type_img=strtolower(JFile::getExt($file));

$db =& JFactory::getDBO();
$query = "UPDATE #__prifoot SET extension2='".$type_img."' WHERE id = '89' ";
$db->setQuery($query);
$db->query();

as you see in this step i want just to get extension of the file and store it in database for just for test, and when i check my database table jos_prifoot i have in the field extension2 null value!

it means that the method strtolower(JFile::getExt($file)) returns a null value. and i dont know why!! is the mistakes in the method JRequest::getVar( 'img2', null, 'files', 'array' ) which i'm using to get file?

Thank you.
hassal
Jun 12 '10 #1
1 8206
You have to convert image into byte array..

but I personally recommend not to store image in database as it will increase unnecessary traffic to your database server and can affect your site performance. So its better to store image somewhere in your web-space and store the path only to the database. Its just my opinion.

Thanks
Manish Choudhary
Oct 12 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Beruang | last post: by
5 posts views Thread by Dav | last post: by
3 posts views Thread by den 2005 | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.