Php : Image uploading and retrieving image from database
Upload image into the database and retrieve from it
See this in video: Image upload
Create the database name as 'image' and just copy this table given below
Database
CREATE TABLE IF NOT EXISTS `upload` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` longblob NOT NULL,
PRIMARY KEY (`id`)
)
Html:
PHP: (upload and display)
mysql_connect("localhost","root","");
mysql_select_db("image");
if(isset($_POST["submit"])){
$filename = addslashes($_FILES['img']['name']);
$tmpname = addslashes(file_get_contents($_FILES['img']['tmp_name']));
$filetype = addslashes($_FILES['img']['type']);
$filesize = addslashes($_FILES['img']['size']);
$array = array('jpg','jpeg');
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!empty($filename)){
if(in_array($ext, $array)){
mysql_query("Insert into upl(name,image) values('$filename','$tmpname')");
echo "uploaded";
}
else{
echo "failed";
}
}
}
//display
$res = mysql_query("SELECT * FROM upl");
while($row = mysql_fetch_array($res)){
$displ = $row['image'];
// please place the single quotation ' instead '
echo '
';
echo "
"; }
See this in video: Image upload
Create the database name as 'image' and just copy this table given below
Database
Html:
"; }
hello
ReplyDeletecan i have the same code with php7 ?
thankyou
Great post! This is very useful for me and gain more information, Thanks for sharing with us.
ReplyDeleteeasyblogging
Guest posting sites
ReplyDeleteOne of the best blogs, where I collected valuable things to know.
PHP Course in Madurai
PHP Training in Madurai
PHP Coaching in Madurai
PHP Course in Coimbatore
PHP Training in Coimbatore
Best PHP Training Institute in Coimbatore