Please follow the below Steps:-
(1) Create a database
CREATE TABLE IF NOT EXISTS `image_upload` (
`image_upload_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(222) NOT NULL,
`image` varchar(222) NOT NULL,
PRIMARY KEY (`image_upload_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
(1) Create a database
CREATE TABLE IF NOT EXISTS `image_upload` (
`image_upload_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(222) NOT NULL,
`image` varchar(222) NOT NULL,
PRIMARY KEY (`image_upload_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
(2) create a folder structure inside your web application folder.
images/company
(3) Create a file upload_image.php
(a) create HTML form using two field name as user_name,image
(b) inside the form tag use attribute enctype="multipart/form-data".
(c) and finally use the following code for inserting values.
$connection = mysql_connect("localhost","root","");
mysql_select_db("hanzala_test",$connection);
?>
if(!empty($_POST))
{
$user_name = $_POST['user_name'];
if(isset($_FILES['image']['name']) && $_FILES['image']['name']!='')
{
$desired_path = 'images/company/';
$rand=rand(0,999);
$desired_file_name = $rand.'_'.str_replace(' ','_',strtolower($_FILES['image']['name']));
move_uploaded_file($_FILES['image']['tmp_name'], $desired_path . $desired_file_name);
}
$query_insert = "INSERT INTO image_upload SET
user_name = '".$user_name."',
image = '".$desired_file_name."'
";
mysql_query($query_insert);
header("location:upload_image.php");exit;
}
?>
For Further Assistance Please Contact to me
(a) create HTML form using two field name as user_name,image
(b) inside the form tag use attribute enctype="multipart/form-data".
(c) and finally use the following code for inserting values.
$connection = mysql_connect("localhost","root","");
mysql_select_db("hanzala_test",$connection);
?>
if(!empty($_POST))
{
$user_name = $_POST['user_name'];
if(isset($_FILES['image']['name']) && $_FILES['image']['name']!='')
{
$desired_path = 'images/company/';
$rand=rand(0,999);
$desired_file_name = $rand.'_'.str_replace(' ','_',strtolower($_FILES['image']['name']));
move_uploaded_file($_FILES['image']['tmp_name'], $desired_path . $desired_file_name);
}
$query_insert = "INSERT INTO image_upload SET
user_name = '".$user_name."',
image = '".$desired_file_name."'
";
mysql_query($query_insert);
header("location:upload_image.php");exit;
}
?>
For Further Assistance Please Contact to me
No comments:
Post a Comment