Multiple image upload with php

<?php include(‘includes/header.php’);
if(isset($_REQUEST[‘add_portfolio’])){

if(isset($_FILES[‘image’][‘name’])){
$filepath = ‘./portfolio/’;
$filename = time().$_FILES[‘image’][‘name’];
move_uploaded_file($_FILES[‘image’][‘tmp_name’],$filepath.$filename);
}

$categories =  implode(“,”,$_POST[‘categories’]);
$data=array();
$data[‘table’][‘name’]=’portfolio’;
$data[‘data’][‘title’]=isset($_POST[‘title’])?$_POST[‘title’]:”;
$data[‘data’][‘port_url’]=isset($_POST[‘port_url’])?$_POST[‘port_url’]:”;
$data[‘data’][‘thumb_image’]=isset($filename)?$filename:”;
$data[‘data’][‘port_categories’] = $categories;
$data[‘data’][‘status’]=isset($_POST[‘status’])?$_POST[‘status’]:”;
$id = $dbfn->insert($data);

if(isset($_FILES[‘gallery’][‘name’])){
$images_arr = array();
foreach($_FILES[‘gallery’][‘name’] as $key=>$val){
$target_dir = “./portfolio-gallery/”;
$filename = time().$_FILES[‘gallery’][‘name’][$key];
$target_file = $target_dir.$filename;
if(move_uploaded_file($_FILES[‘gallery’][‘tmp_name’][$key],$target_file)){
$images_arr[] = $target_file;
}
$queryimage=”INSERT INTO portfolio_gallery(port_id,gallery_image,created_date) VALUES(‘$id’,’$filename’,NOW())”;
mysql_query($queryimage);
}
}

if(!empty($id)){
echo”window.location.href=’portfolio.php?msg=add’;”;
}
}

$getcategories = $dbfn->getAlldata(‘portfolio_categories’);
?>
https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
http://js/jquery.form.js

$(document).ready(function(){
$(‘#images’).on(‘change’,function(){
$(‘#multiple_upload_form’).ajaxForm({
target:’#images_preview’,
beforeSubmit:function(e){
$(‘.uploading’).show();
},
success:function(e){
$(‘.uploading’).hide();
},
error:function(e){
}
}).submit();
});
});

<aside class=”right-side”>
<!– Content Header (Page header) –>
<section class=”content-header”>
<h1>
Portfolio
<small>portfolio</small>
</h1>
<ol class=”breadcrumb”>
<li><a href=”cvdashBoard.php”><i class=”fa fa-dashboard”></i> Home</a></li>
<li><a href=”#”>Portfolio</a></li>
<li class=”active”>Add New Portfolio</li>
</ol>
</section>

<!– Main content –>
<section class=”content”>

Portfolio

<!– /.box-header –>
<!– form start –>
<form role=”form” method=”post” action=”” enctype=”multipart/form-data”>

Portfolio Title

Portfolio Url

Example: http://www.google.com

Portfolio Image

Portfolio Gallery Image

Portfolio Categories

” name=”categories[]”>

<?php } ?>
</div>

Status

InActive
Active

</div>

</div><!– /.box-body –>

</form>

</div><!– /.box –>

</div><!–/.col (left) –>

</div>   <!– /.row –>
</section><!– /.content –>
</aside><!– /.right-side –>
<?php include(‘includes/footer.php’);?>

document.getElementById(“portfolioimage”).onchange = function () {
var extensions = new Array(“jpg”,”jpeg”,”gif”,”png”,”bmp”);
var imagename = document.getElementById(“portfolioimage”).value;
var imagelength = imagename.length;

var pos = imagename.lastIndexOf(‘.’) + 1;

var ext = imagename.substring(pos, imagelength);

var final_ext = ext.toLowerCase();
var j = ‘0’;
for (i = 0; i

Advertisements