I am unable to upload a image in the destination folder in codeigniter, I created one controller under the controller/admin folder with a name called site. And I added one model under the model folder with a name called model_view, and finally I created one view in the view folder with a name called view_addsite. And I created one table in the mysql with a name called sitesettings and 14 columns are added in that table. Problem hear is all fields are added in the table except image. please find the code.
controller(site)::
===========
public function add()
{
$datte = date('Y-m-d H:i:s');
if(!$this->input->post('buttonSubmit'))
{
$data['message'] = '';
$this->load->view('admin/view_addsite', $data);
}
else
{
//$this->load->library('form_validation');
if($this->form_validation->run('addsite'))
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_width'] = '2048';
$config['max_height'] = '2048';
$this->load->library('upload', $config);
$title = $this->input->post('title');
$name = $this->input->post('name');
$admin = $this->input->post('admin');
$mail = $this->input->post('mail');
$phone = $this->input->post('phone');
$contact=$this->input->post('contact');
$fb=$this->input->post('fb');
$tw=$this->input->post('tw');
$yt=$this->input->post('yt');
$in=$this->input->post('in');
$gp=$this->input->post('gp');
$ft=$this->input->post('ft');
$this->upload->do_upload('image');
$data = $this->upload->data('image');
$image= $data['file_name'];
$this>model_site>
insert($title,$image,$name,$admin,$mail,
$phone,$contact,$fb,$tw,$yt,$in,$gp,$ft);
$this->session->set_flashdata('message','site Successfully
Created.');
redirect(base_url('admin/site'));
}
else
{
$data['message'] = validation_errors();
$this->load->view('admin/view_addsite', $data);
}
}
}
Model(model_site)::
===================
public function
insert($title,$image,$name,$admin,$mail,$phone,$contact,
$fb,$tw,$yt,$in,$gp,$ft)
{
$data = array(
'admintitle' => $title,
'logo' => $image,
'fromname' => $name,
'adminemail'=> $admin,
'receivemail' => $mail,
'phonenumber' => $phone,
'contactaddress' => $contact,
'facebook' => $fb,
'twitter'=>$tw,
'youtube' => $yt,
'instagram' => $in,
'googleplus' => $gp,
'footer' => $ft,
);
$this->db->insert('sitesettings', $data);
}
view(view_addsite)::
===================
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_left">
<h3>Sitesettings</h3>
</div>
</div><div class="clearfix"></div>
<hr>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Add a new Site</h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i class="fa fa-
chevron-up"></i></a></li>
<li><a class="close-link"><i class="fa fa-close">
</i></a></li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
<label><?php echo $message; ?></label>
<form method="post">
<fieldset>
<div class="form-group">
AdminPage Title : <input class="form-control"
placeholder="Admin Title" name="title" id="title"
type="text" ><span id="user-availability-status">
</span>
<div class="form-group">
Select image to upload:
<input type="file" name="fileToUpload"
id="fileToUpload">
</form>
<div class="form-group">
From Name : <input class="form-control"
placeholder="Form Title" name="name" id="name" type="text"
><span id="user-availability-status"></span>
<div class="form-group">
Admin Email Address : <input class="form-control"
placeholder="Admin Email" name="admin" id="admin"
type="text" onBlur="checkAvailability()" ><span
id="user-availability-status"></span>
<div class="form-group">
Receive Mail Address for Contact Us Form : <input
class="form-control" placeholder="Receive Email"
name="mail" id="mail" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Phone number: <input class="form-control"
placeholder="Phone Number" name="phone" id="phone"
type="text" onBlur="checkAvailability()" ><span id="user-
availability-status"></span>
</div>
<div class="form-group">
Contact Adress : <input class="form-control"
placeholder="Contact Address" name="contact" id="contact"
type="text" onBlur="checkAvailability()" ><span
id="user-availability-status"></span>
</div>
<div class="form-group">
Facebook : <input class="form-control" placeholder="Facebook"
name="fb" id="fb" type="text" onBlur="checkAvailability()" >
<span id="user-availability-status"></span>
</div>
<div class="form-group">
Twitter : <input class="form-control" placeholder="Twitter"
name="tw" id="tw" type="text" onBlur="checkAvailability()" >
<span id="user-availability-status"></span>
</div>
<div class="form-group">
Youtube : <input class="form-control"
placeholder="Youtube" name="yt" id="yt" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Instagram : <input class="form-control"
placeholder="Instagram" name="in" id="in" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Google Plus: <input class="form-control"
placeholder="Google Plus" name="gp" id="gp" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Footer: <input class="form-control"
placeholder="Footer" name="ft" id="ft"
type="text" onBlur="checkAvailability()" ><span id="user-
availability-status"></span>
</div>
<input type="submit" name="buttonSubmit"
value="add" class="btn btn-success" />
</fieldset>
</form>
</div> <!-- /content -->
</div><!-- /x-panel -->
</div> <!-- /col -->
</div> <!-- /row -->
</div>
</div> <!-- /.col-right -->
<!-- /page content -->
<?php $this->load->view('admin/partials/admin_footer'); ?>
<?php if($this->session->flashdata('message') != NULL) : ?>
<script>
swal({
title: "Success",
text: "<?php echo $this->session->flashdata('message'); ?>",
type: "success",
timer: 1500,
showConfirmButton: false
});
</script>
<?php endif ?>
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
for more detail see:upload file with codeigniter
You are missing
enctype="multipart/form-data"
on your form tag and also remove the </form> just after the image input box.
Controller:
$doc_1 = "uploads/img_1/";
if (isset($_FILES['userfile_1']) && !empty($_FILES['userfile_1'])) {
$filename = pathinfo($_FILES['userfile_1']['name']);
if (move_uploaded_file($_FILES['userfile_1']['tmp_name'], $doc_1.$filename['basename'])) {
$attch_1 = base_url().$doc_1.$filename['basename'];
}
else {
$attch_1 = "na";
}
}
view:
<?php echo form_open_multipart("store_property", ['class'=>'form-horizontal']); ?>
<input type="file" name="userfile_1" />
Related
Been trying out codeigniter and wanted to create a form with file upload using the upload class. However when i try to save the form, it didn't respond and just show the same page. I've been looking around, but I can't seem to find out how to make this work.
This is the controller Product.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
Class Product extends CI_Controller{
function __construct(){
parent::__construct();
check_not_login();
$this->load->model('product_m');
}
public function index(){
$data['row'] = $this->product_m->get();
$this->template->load('template', 'product/data/product_data', $data);
}
public function add(){
$product = new stdClass();
$product->product_id = null;
$product->product_name = null;
$product->customer_name = null;
$product->supplier_name = null;
$product->weight = null;
$product->product_date = null;
$product->expired_date = null;
$product->image = null;
$product->barcode = null;
$data = array(
'page' => 'add',
'row' => $product
);
$this->template->load('template', 'product/data/product_form', $data);
}
public function edit($id){
$query = $this->product_m->get($id);
if($query->num_rows()>0){
$product = $query->row();
$data = array(
'page' => 'edit',
'row' => $product
);
$this->template->load('template', 'product/data/product_form', $data);
}else{
echo "<script>alert('Data not found');";
echo "window.location='".site_url('product')."';</script>";
}
}
public function process(){
$post = $this->input->post(null, TRUE);
if(isset($_POST['add'])){
$config['upload_path'] = './uploads/product';
$config['allowed_types'] = 'jpeg|pdf|jpg|png|doc|docs|xls|xlsx';
$config['max_size'] = 5120;
$config['file_name'] = 'product-'.date('ymd').'-'.substr(md5(rand()),0,10);
$this->load->library('upload', $config);
if(#$_FILES['image']['name'] !=null){
if($this->upload->do_upload('image')){
$post['image'] = $this->upload->data('file_name');
$this->product_m->add($post);
if($this->db->affected_rows() > 0){
$this->session->set_flashdata('success', 'Data saved successfully');
}
redirect('product');
}else{
$error = $this->upload->display_errors();
$this->session->set_flashdata('error', $error);
redirect('product/add');
}
}
else{
$post['image'] = null;
$this->product_m->add($post);
if($this->db->affected_rows() > 0){
$this->session->set_flashdata('success', 'Data saved successfully');
}
redirect('product');
}
}else if(isset($_POST['edit'])){
$this->product_m->edit($post);
}
}
public function del($id){
$this->product_m->del($id);
if($this->db->affected_rows() > 0){
$this->session->set_flashdata('Success', 'Data successfully deleted');
}
redirect('product');
}
}
Script for the form product_form.php
<section class="content-header">
<h1>
Product
<small>Add product</small>
</h1>
</section>
<section class ="content">
<div class="box">
<div class="box-header">
<h3 class="box-title"> product</h3>
<div class="pull-right">
<a href="<?=site_url('product')?>" class="btn btn-warning btn-flat">
<i class="fa fa-undo"></i> Back
</a>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?php echo form_open_multipart('product/process');?>
<div class="form-group">
<label>Product Name *</label>
<input type="hidden" name="id" value="<?=$row->product_id?>">
<input type="text" name="product_name" value="<?=$row->product_name?>" class="form-control" required>
</div>
<div class="form-group">
<label>Customer Name *</label>
<input type="text" name="customer_name" value="<?=$row->customer_name?>" class="form-control" required>
</div>
<div class="form-group">
<label>Supplier Name *</label>
<input type="text" name="supplier_name" value="<?=$row->supplier_name?>" class="form-control" required>
</div>
<div class="form-group">
<label>Weight(kg) *</label>
<input type="number" name="weight" value="<?=$row->weight?>" class="form-control" required>
</div>
<div class="form-group">
<label>Product Date(dd/mm/yyyy) *</label>
<input type="text" name="product_date" value="<?=$row->product_date?>" class="form-control" required>
</div>
<div class="form-group">
<label>Expired Date(dd/mm/yyyy) *</label>
<input type="text" name="expired_date" value="<?=$row->expired_date?>" class="form-control" required>
</div>
<div class="form-group">
<label>Technical Data</label>
<input type="file" name="image" class="form-control" >
</div>
<!-- FORM BARCODE -->
<div class="form-group">
<label>Barcode</label>
<input name="barcode" class="form-control" value="
<?php
$angka = rand(1000000,9999999);
$random = rand(0,25);
$random1 = rand(0,25);
$random2 = rand(0,25);
$name = array("A", "B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y","Z");
echo $name[$random],$name[$random1],$name[$random2],$angka;
$row->barcode
?>" readonly>
</div>
<div class="form-group">
<button type="submit" name="<?=$page?>" class="btn btn-success btn-flat">
<i class="fa fa-paper-plane"> Save</i>
</button>
<button type="Reset" class="btn btn-flat"> Reset</button>
</div>
<!-- </form> -->
<?php echo form_close();?>
</div>
</div>
</div>
</div>
</section>
Load the form helper.
function __construct(){
parent::__construct();
check_not_login();
$this->load->model('product_m');
$this->load->helper('form');
}
I'm trying to insert data into database through a form. I'm uploading 2 image files, in database path of the files will be stored. I'm trying to do server side validation. when user does not upload a file or when user is uploading wrong file type, an error messages should display and page should return to same page with no data inserted into database.
This is my view:
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-md-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Add News & Event</h4>
<p class="card-description"> </p>
<?php echo validation_errors("<div class='alert alert-danger'>","</div>");?>
<?php if($failed = $this->session->flashdata('addNewsFailed')){
echo '<div class="alert alert-danger">' ;
echo $failed;
echo '</div>';
}?>
<form class="forms-sample" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputName1">Title</label>
<input type="text" class="form-control" id="exampleInputName1" value="<?php echo
set_value("title");?>" name="title">
</div>
<div class="form-group">
<label for="exampleInputName1">Sub Title</label>
<input type="text" class="form-control" id="exampleInputName1" value="<?php echo set_value("sub");?>" name="sub_title">
</div>
<div class="form-group">
<label for="exampleInputName1">Event Date</label>
<input type="text" class="form-control" id="exampleInputName1" name="date" value="<?php echo date('d - M - y ');//echo set_value("date");?>">
</div>
<div class="container">
<div class="row">
<div class="col-md">
<div class="form-group">
<label>Feature Image</label>
<div class="input-group col-xs-12">
<input type="file" class="form-control file-upload-info" placeholder="Upload Image" name="img" style="z-index: 9999; opacity: 0;" id="image">
<div id="imageName"></div>
<span class="input-group-append">
<button class="file-upload-browse btn btn-info" type="button" style="position: absolute; left: 0; padding: 6px 23px;border-radius:3px;">Upload</button> </span>
</div>
<?php if(isset($upload_error)){
echo $upload_error;
}?>
</div>
</div>
<div class="col-md">
<div class="form-group">
<label> Banner Image</label>
<div class="input-group col-xs-12">
<input type="file" class="form-control file-upload-info" placeholder="Upload Image" name="banner" id="banner" style="opacity: 0; z-index: 9999;">
<div id="bannerName"></div>
<span class="input-group-append">
<button class="file-upload-browse btn btn-info" type="button" style="position: absolute;left: 0;padding: 6px 23px;border-radius: 3px;">Upload</button></span>
</div>
<?php if(isset($upload_error1)){
echo $upload_error1;
}?>
</div>
</div>
</div>
</div>
<span class="input-group-append">-->
<div class="form-group">
<label for="exampleTextarea1">Text</label>
<textarea class="form-control" id="exampleTextarea1" rows="2" name="para" value=""><?php echo set_value("para");?></textarea>
</div>
<button type="submit" class="btn btn-success mr-2">Add</button>
<button class="btn btn-light">Cancel</button>
</form>
</div>
</div>
</div>
</div>
</div>
This is my controller:
public function addEvent()
{
//load library
$this->load->library('form_validation');
$this->load->helper('form');
//set rules for validation
$this->form_validation->set_rules("title", "Title", "required");
$this->form_validation->set_rules("date", "Event Date", "required");
$this->form_validation->set_rules("para", "Text", "required");
//template
$this->output->set_template('admin_layout');
//image upload
$config = [
'upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
];
$this->load->library('upload', $config);
//validation
if ($this->form_validation->run()) {
$post = $this->input->post();
if (!$this->upload->do_upload('img')) {
$upload_error = $this->upload->display_errors();
$this->load->view('dashboard/pages/forms/addEvent', compact('upload_error'));
} else {
$Feature1 = $this->upload->data();
$image_path = base_url('uploads/' . $Feature1['raw_name'] . $Feature1['file_ext']);
$post['image_path'] = $image_path;
}
if (!$this->upload->do_upload('banner')) {
$upload_error1 = $this->upload->display_errors();
$this->load->view('dashboard/pages/forms/addEvent', compact('upload_error1'));
} else {
$carsousel = $this->upload->data();
$banner = base_url('uploads/' . $carsousel['raw_name'] . $carsousel['file_ext']);
$post['banner'] = $banner;
}
$this->load->model('loginmodel', 'addNews');
$insert_id = $this->addNews->addNews($post);
if ($insert_id) {
$this->session->set_flashdata("addNewsSuccess", 'News & Event Added Successfully');
redirect('dashboard/update_news/' . $insert_id);
} else {
$this->session->set_flashdata("addNewsFailed", 'Failed');
$this->load->view('dashboard/pages/forms/addEvent');
}
} else {
$upload_error = $this->upload->display_errors();
$this->load->view('dashboard/pages/forms/addEvent', compact('upload_error'));
}
}
This is my model:
public function addNews($array)
{
$this->db->insert('news', $array);
return $this->db->insert_id();
}
My form validation are working perfectly but when user is uploading wrong file type or does not upload any file then file upload error message is not displaying and data is inserting into database the with both image field empty.
I have a problem with uploading images in the database in codeigniter. When I upload image in the database, it shows this type of error like:
The upload path does not appear to be valid. So what's the problem in this code. I cannot figure out, so please help me.
I tried base_url() method also but error is not solved...!
My Htmlcode:-
<?php echo form_open_multipart('student/insertstudent') ?>
<form>
<div class="panel panel-primary" >
<div class="panel-heading" >
<p class="label" style="font-size: 15px">Student Registration Form</p>
</div>
<div class="panel-body">
<fieldset>
<div class="form-group">
<label for="exampleInputEmail1">First Name</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter First Name" name="fname" value="<?php echo set_value('fname'); ?>">
<div class="row-lg-6">
<?php echo form_error('fname'); ?>
</div>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Last Name</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Enter Last Name" name="lname" value="<?php echo set_value('lname'); ?>">
<div class="row-lg-6">
<?php echo form_error('lname'); ?>
</div>
</div>
<div class="form-group">
<label for="exampleTextarea">Address</label>
<textarea class="form-control" id="exampleTextarea" rows="2" placeholder="Enter Address" name="add"><?php echo set_value('add'); ?></textarea>
<div class="row-lg-6">
<?php echo form_error('add'); ?>
</div>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Contact Number</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Enter Contact Number" name="cno" value="<?php echo set_value('cno'); ?>">
<div class="row-lg-6">
<?php echo form_error('cno'); ?>
</div>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Emaid ID</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Enter your email" name="email" value="<?php echo set_value('email'); ?>">
<div class="row-lg-6">
<?php echo form_error('email'); ?>
</div>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Enter Course</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="Enter Course Name" name="cname" value="<?php echo set_value('cname'); ?>">
<div class="row-lg-6">
<?php echo form_error('cname'); ?>
</div>
</div>
<!-- <div class="form-group">
<label for="exampleInputPassword1">Select Student Photo</label>
<input type="file" class="form-control" id="exampleInputPassword1" placeholder="Enter Course Name" name="photo">
<div class="row-lg-6">
<?php echo form_error('photo'); ?>
</div>
</div> -->
<div class="form-group">
<label for="exampleInputPassword1">Select Image</label>
<?php echo form_upload(['name' => 'userfile','class'=>'form-control']); ?>
<div class="row-lg-6">
<?php if(isset($upload_error))
{
echo $upload_error;
} ?>
</div>
</div>
<h4 align="center" style="margin-left: -150px"><button type="submit" class="btn btn-primary">Register</button></h4>
<h4 align="center" style="margin-top: -43px;margin-left: 200px"><button type="reset" class="btn btn-primary">Reset</button></h4>
</fieldset>
</div>
</div>
my controller file:-
public function insertstudent()
{
$this->form_validation->set_rules('fname', 'FirstName', 'required|alpha');
$this->form_validation->set_rules('lname', 'lastName', 'required|alpha');
$this->form_validation->set_rules('add', 'Address', 'required');
$this->form_validation->set_rules('cno', 'Contact Number', 'required|numeric');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('cname', 'Course Name', 'required');
// $this->form_validation->set_rules('userfile', 'Student Photo', 'required');
$this->form_validation->set_error_delimiters("<p class='text-danger'>", "</p>");
$config['upload_path'] = base_url('asset/uploads/');
$config['allowed_types'] = 'gif|jpg|png';
$this->upload->initialize($config);
$this->load->library('upload',$config);
if ($this->form_validation->run() == TRUE && $this->upload->do_upload('userfile')) {
$post = $this->input->post();
$data = $this->upload->data();
$image_path = base_url("upload/".$data['raw_name'].$data['file_ext']);
$post['image_path'] = $image_path;
$this->load->model('useradd');
if($this->useradd->addstudent($post)){
$this->session->set_flashdata('success', 'Record Successfully Inserted');
return redirect('admin');
}else {
$this->load->view('addstudent');
}
// $data = array(
// 'firstname' => $this->input->post('fname'),
// 'lastname' => $this->input->post('lname'),
// 'address' => $this->input->post('add'),
// 'phone' => $this->input->post('cno'),
// 'email' => $this->input->post('email'),
// 'course' => $this->input->post('cname'),
// 'photo' => $image_path,
// );
// // $this->load->library('upload', $data);
// if ($result == true) {
// $this->session->set_flashdata('success', 'Record Successfully Inserted');
// return redirect('admin');
// } else {
// $this->load->view('addstudent');
// }
} else {
$upload_error = $this->upload->display_errors();
$this->load->view('addstudent',compact('upload_error'));
}
}
my Model:-
class useradd extends CI_Model
{
function addstudent($data)
{
$result = $this->db->insert('add_student', $data);
}
}
My error is:
The upload path does not appear to be valid.
Try This Code To Upload Image.and remove form tag in your view file and you didn't define form_close method at the end of the form of your view file
$file = $_FILES['filename']['name'];
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->do_upload();
$allData = $this->upload->data();
myiamge
I have 2 forms as tab in signup page when one form is submit and if have any error I want to redirect to that specific tab which have error but did not happen.
Here is my view
<?php include 'header.php'; ?>
<section class="services">
<div class="container">
<div class="signup-wrapper well" style="margin-bottom: 80px; margin-top: 80px;">
<div class="container">
<div class="services__main">
<h2 class="title title--main"><span class="title__bold">Sign Up</span><span class="line line--title"><span class="line__first"></span><span class="line__second"></span></span></h2>
</div>
<div class="aside-tabs__links">
Genrel User
Dealership
</div>
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="desc" >
<div class="col-md-5">
<form action="<?= base_url();?>Home/add_user" method="post" >
<!-- class="quick-form" -->
<div class="form-group">
<input type="text" class="form-control" name="fname" placeholder="Full Name" />
</div>
<?php echo form_error('fname'); ?>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email" />
</div>
<?php echo form_error('email'); ?>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" />
</div>
<?php echo form_error('password'); ?>
<div class="form-group">
<input type="text" class="form-control" name="phone" placeholder="Phone #" />
</div>
<?php echo form_error('phone'); ?>
<div class="form-group">
<select class="select-2 form-control" name="city">
<option>Select City</option>
<?php foreach ($results as $result) { ?>
<option><?= $result->city; ?></option>
<?php } ?>
</select>
</div>
<?php echo form_error('city'); ?>
<div class="form-group">
<input type="submit" class="btn button button--red button--main pull-right" style="margin-bottom: 10px;" value="Sign Up">
</div>
</form>
</div>
</div>
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="rev" style="display: none;">
<div class="col-xs-5">
<form action="<?= base_url();?>Home/add_dealer" method="post" enctype="multipart/form-data">
<h4>Comapny Information</h4>
<hr>
<div class="form-group">
<input type="text" class="form-control" name="cname" placeholder="Company Name" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="owner" placeholder="Owner Name" />
</div>
<div class="form-group">
<select class="select-2 form-control" name="city">
<option>Select City</option>
<?php foreach ($results as $result) { ?>
<option><?= $result->city; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" name="address" placeholder="Office Location" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="phone" placeholder="Office Phone" />
</div>
<div class="form-group">
<select name="business-type" class="form-control">
<option class="form-group">Products Deal</option>
<option class="form-group">Bikes</option>
<option class="form-group">Accessories</option>
<option class="form-group">Both</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" name="link" placeholder="social-link(optional)" />
</div>
<div class="form-group">
<button type="button" class="button button--custom--grey button--main btn" id="logo">Upload Logo</button>
<input type="file" class="form-control hidden" id="logo1" name="logo1" /><span id="mylogo">* Format must be jpg,jpeg or png</span>
</div>
<?php echo form_error('logo'); ?>
<div class="form-group">
<textarea class="form-control" name="descrp" placeholder="Description(optional)"></textarea>
</div>
<h4>Primary Information</h4>
<hr>
<div class="form-group">
<input type="text" class="form-control" name="email" placeholder="Email" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="password" placeholder="Password" />
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn button button--red button--main pull-right" value="Sign Up">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<?php include 'footer.php'; ?>
here is my controller
function add_dealer()
{
//echo "<pre>"; print_r($_FILES);
$config['upload_path'] = 'C:\xampp\htdocs\devilbirds\images\uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name'] = 'TRUE';
$config['overwrite'] = 'FALSE';
$config['wm_text'] = 'Deveil Birds';
$config['wm_type'] = 'text';
$config['wm_font_path'] = 'C:\xampp\htdocs\devilbirds/fonts/fontawesome-webfont.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'aabbcc';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';
$this->load->library('upload', $config);
$this->image_lib->watermark();
$abc = $this->upload->do_upload('logo1');
$upload_data = $this->upload->data();
// var_dump($abc);exit();
$file_name = $upload_data['file_name'];
$this->form_validation->set_rules('cname','CName','trim|required');
$this->form_validation->set_rules('logo1','Logo1','trim');
$this->form_validation->set_rules('address','Address','trim');
$this->form_validation->set_rules('phone','Phone','trim|is_unique[bd_dealer.phone]');
$this->form_validation->set_rules('owner','Owner','trim');
$this->form_validation->set_rules('descrp','Descrp','trim');
$this->form_validation->set_rules('business-type','Business-type','trim');
$this->form_validation->set_rules('link','Link','trim');
$this->form_validation->set_rules('email','Email','trim|is_unique[bd_dealer.email]');
$this->form_validation->set_rules('password','Password','trim|min_length[5]|max_length[20]');
$this->form_validation->set_rules('city','City','trim');
if ($this->form_validation->run() == FALSE)
{
$data['error'] = $this->session->set_flashdata('errors');
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url
}
else
{
$userData = array(
'company' => $this->input->post('cname'),
'logo' => $file_name,
'location' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
'name' => $this->input->post('owner'),
'description' => $this->input->post('descrp'),
'business_type' => $this->input->post('business-type'),
'social_link' => $this->input->post('link'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'city' => $this->input->post('city'));
$data = array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'user_type' => '2');
//var_dump($userData);exit();
$this->Home_m->add_dealer($userData);
$this->Home_m->users($data);
redirect('Home/login');
}
}
I have two functions for two different forms in tabs. let suppose if i post my dealer form and this form have any issue then it will redirect to the signup page and it shows the pre-active tab which is general user signup. i want to redirect to the div that contain the form or dealer signup. any help will be appreciated , thanks in advance
In your controller when you get error do this.
for form one error
$data['error'] = $this->session->set_flashdata('errors');
$data['div1'] = "div1";
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url ,i have pass div1 as parameter
For form two error
$data['error'] = $this->session->set_flashdata('errors');
$data['div2'] = "div2";
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url ,i have pass div1 as parameter
In your view page
<script>
$(document).ready(function(){
var div1 = "<?php $div1; ?>";
var div2 = "<?php $div2; ?>";
if(div1=='' && div2==''){
$("#desc").show();
$("#rev").hide();
}else if(div1=='div1' && div2==''){
$("#desc").show();
$("#rev").hide();
}else if(div1=='' && div2=='div2'){
$("#desc").hide();
$("#rev").show();
}
})
</script>
div1
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="desc">
Div2
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="rev">
I hope it will help you.
I have 2 websites in 1 htdocs directory. The structure's like this
The main directory it's structured like this(name:Quartiere):
Quartiere
_admin
application
assets
Second website directory it's _admin with the same structure(default CodeIgniter structure).
I'm trying to upload a file from _admin to the main directory assets folder, but for some reason, it's not working.I tried other answers from other post but nothing it helped.
What I tried:
Put 'userfile' in do_upload
Checked if the form it's multipart(it is)
What I checked:
If the path it's good(it is)
If the size of the photo it's smaller than 2048(it is)
_admin Controller:
public function add_product(){
if(!$this->session->userdata('logged_in')){
redirect('users/login');
}
$data['title'] = 'Adauga Produs';
$data['categories'] = $this->category_model->get_categories();
$this->form_validation->set_rules('name','Nume','required');
$this->form_validation->set_rules('category','Categorie','required');
$this->form_validation->set_rules('ingredients','Ingrediente');
$this->form_validation->set_rules('price','Pret','required');
$this->form_validation->set_rules('grams','Gramaj','required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('products/adauga', $data);
$this->load->view('templates/footer');
}else{
//upload image
$config['upload_path'] = 'http://localhost/quartiere/assets/images';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload',$config);
if(!$this->upload->do_upload('userfile')){
$errors = array('error' => $this->upload->display_errors());
$food_image = 'noimage.png';
}else{
$data = array('upload_data' => $this->upload->data());
$food_image = $_FILES['userfile']['name'];
}
$this->food_model->add_product($food_image);
redirect('produse/adauga');
}
}
_admin View:
<?php echo validation_errors();?>
<?php echo form_open_multipart('products/add_product');?>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">
<?php echo $title; ?>
</h1>
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Nume Produs" required/>
</div>
<div class="form-group">
<select class="form-control" name="category" required>
<?php foreach($categories as $category):?>
<option value="<?php echo $category['id'];?>"><?php echo $category['category_name'];?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group">
<label>Bar:</label><br>
Da <input type="radio" name="bar" class="from-control" value="1"/>
Nu <input type="radio" name="bar" class="from-control" value="0"/>
</div>
<div class="form-group">
<input type="text" name="ingredients" class="form-control" placeholder="Ingrediente"/>
</div>
<div class="form-group">
<input type="number" name="grams" class="form-control" placeholder="Gramaj"/>
</div>
<div class="form-group">
<label>Poza:</label>
<input type="file" name="userfile" size="10"/>
</div>
<div class="form-group">
<input type="number" name="price" class="form-control" placeholder="Pret" required/>
</div>
<button type="submit" class="btn btn-success btn-block">Adauga Produs</button>
</div>
</div>
<?php form_close(); ?>
You can make the upload path to - '../assets/images' - or - $_SERVER['DOCUMENT_ROOT'].'/quartiere/assets/images'. Either way is fine.