can anybody please tell me how to insert and retrieve an image stored in a database using php and mysql.the way i m doing now is by storing the file in a server and filename in the db.but the problem with that is while retrieving the image doesnt show up.db entries are all correct..but due to some reason i cant display the file in my webpage.please help...dis is very urgent.i m badly running out of time..thanx in advance

Personally I would not use the second example-saving images into the Database, there is no need.

The filesystem was designed to do this job so why re-invent the wheel? I have yet to come across a scenario where storing images in the database is better than the filesystem.

thank u so much for ur instant reply.i'll try to qoute my problem here

its like this..

//retrieve the filename from db using a select query
$result= mysql_result("SELECT imagename  FROM imagetab");
$row=mysql_fetch_array($result);
//then i placed an image object with dynamic source like this
<img src="<?php echo $row[0]; ?>"/>

This is works fair in a localmachine with host as localhost but when deploys it in the hosting space and run as a normal web page i just can't stand it ,i cant see the image.and i am not able to think of reasonable answer.can u help me out of this?

thank u for all who spared a moment to look into my problem.finally i got the answer the problem is with my upload code to upload the image .now i want to sort it out.so again i need help from ur side .how to set file permissions using php

take a look at this fuction:
chmod($pro_imgpath,0777);

<?php
// Read and write for owner, nothing for everybody else
chmod("test.txt",0600);

// Read and write for owner, read for everybody else
chmod("test.txt",0644);

// Everything for owner, read and execute for everybody else
chmod("test.txt",0755);

// Everything for owner, read for owner's group
chmod("test.txt",0740);
?>

And 777- Everybody (i.e. others) has full rights.

Or while uploading it using an FTP client just right click on the folder or file and go to properties. There change the access levels by just typing in the code eg: 777 etc....


ps: do this to the files already on the server

Personally I would not use the second example-saving images into the Database, there is no need.

The filesystem was designed to do this job so why re-invent the wheel? I have yet to come across a scenario where storing images in the database is better than the filesystem.

For one thing, it makes password protection of images much easier to work with and more secure.

This article has been dead for over six months. Start a new discussion instead.