jQuery File Upload SELECT in mysql by gallery ID - php

I would like a help with jQuery File Upload, I'm sorry if my English is not correctI would like to show the images by passing an ID parameter through the url or some hidden field because I have a gallery and each gallery has its images.
<div class="container-fluid">
<!-- The file upload form used as target for the file upload widget -->
<!-- estava assim action="//jquery-file-upload.appspot.com/"-->
<form id="fileupload" action="server/php/UploadHandler" method="POST" enctype="multipart/form-data">
<!-- Redirect browsers with JavaScript disabled to the origin page -->
<noscript>
<input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/">
</noscript>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="col-lg-7">
<!-- The fileinput-button span is used to style the file input field as button -->
<!--the hidden input is used to get id by GET in the parameter to urledit= -->
<input type="hidden" name="urledit" value="<?php echo $urledit; ?>">
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Add fotos...</span>
<input type="file" name="files[]" multiple>
</span>
<button type="submit" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Iniciar upload</span>
</button>
<button type="reset" class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancelar upload</span>
</button>
<button type="button" class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Apagar</span>
</button>
<input type="checkbox" class="toggle">
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="col-lg-5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
</form>
</div>
Database class:
<?php
include_once 'config.php';
class conn extends config
{
var $pdo;
function __construct()
{
$this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->user, $this->pass);
}
function getImages($urledit)
{
//$urledit = '9';
$stm = $this->pdo->prepare("SELECT gallery_img FROM site_gallery WHERE gallery_galeria_id = '$urledit'");
$run = $stm->execute();
$array = array();
while ($rs = $stm->fetch(PDO::FETCH_ASSOC)) {
array_push($array,$rs['gallery_img']);
}
return $array;
}
function deleteImages($foto)
{
$stm = $this->pdo->prepare("DELETE FROM site_gallery WHERE gallery_img = :foto");
$stm->bindValue(":foto",$foto);
$run = $stm->execute();
}
function insertImages($id,$foto,$data)
{
try{
$stm = $this->pdo->prepare("INSERT INTO site_gallery (gallery_galeria_id, gallery_img, gallery_data) VALUES (:id,:foto,:data)");
$stm->bindValue("id",$id);
$stm->bindValue("foto",$foto);
$stm->bindValue("data",$data);
$run = $stm->execute();
//echo $stm->rowCount();
}catch(PDOException $e){
echo 'Error: '. $e->getMessage();
}
}
}
?>
UploadHandler.php
to insert into the database works
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = new \stdClass();
$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
$index, $content_range);
$file->size = $this->fix_integer_overflow((int)$size);
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
mkdir($upload_dir, $this->options['mkdir_mode'], true);
}
$file_path = $this->get_upload_path($file->name);
$append_file = $content_range && is_file($file_path) &&
$file->size > $this->get_file_size($file_path);
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
//insere no banco
$data = date('Y-m-d H:i:s');
$urledit = $this->get_url_edit('urledit');
$conn = new conn();
$conn->insertImages($urledit,$file->name,$data);
$conn->getImages($urledit);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
but this select does not work:
protected function get_file_objects($iteration_method = 'get_file_object') {
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
return array();
}
$urledit = $this->get_url_edit('urledit');
//$urledit = '9';
$conn = new conn();
$Images = $conn->getImages($urledit);
return array_values(array_filter(array_map(
array($this, $iteration_method),
//scandir($upload_dir)
$Images
)));
}
because it has no value for $Images = $conn->getImages($urledit);
can anybody help me?
Alguém poderia me ajudar? pode ser em português também.

Related

How to create Insert data via Excel upload which contains half of mysql table

my Controllers
public function uploadexcel()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'xlsx|xls';
$config['file_name'] = 'doc' . time();
$this->load->library('upload', $config);
if ($this->upload->do_upload('importexcel')) {
$file = $this->upload->data();
$reader = ReaderEntityFactory::createXLSXReader();
$reader->open('uploads/' . $file['file_name']);
foreach ($reader->getSheetIterator() as $sheet) {
$numRow = 1;
foreach ($sheet->getRowIterator() as $row) {
if ($numRow > 1) {
$datareceiving = array(
'lot_number' =>$this->m_receiving->joinMasterpartBarcode()."/" . $this->m_receiving->bln() . "/" . $this->m_receiving->tgl() . "/" . $this->m_receiving->getSerialNumber(),
'upload_id' => $this->m_receiving->get_no_upload_id(),
'number_part' => $row->getCellAtIndex(0),
'description' => $row->getCellAtIndex(1),
'shift' => $row->getCellAtIndex(2),
'date_production' => $row->getCellAtIndex(3),
'date_receive' => $row->getCellAtIndex(4),
'qty_transfer' => $row->getCellAtIndex(5),
'pic' => $row->getCellAtIndex(6),
'txndate' => $this->m_receiving->today(),
);
$this->m_receiving->import_data($datareceiving);
}
$numRow++;
}
$reader->close();
unlink('uploads/' . $file['file_name']);
$this->session->set_flashdata('success', 'Import Excel berhasil');
redirect('receiving');
}
} else {
echo "Error : " . $this->upload->display_errors();
}
}
public function exportexcel()
{
$get = $this->m_receiving->getAll();
// Validasi jumlah
$get->num_rows();
$writer = WriterEntityFactory::createXLSXWriter();
$writer->openToBrowser('Receiving.xlsx');
$header =
[
WriterEntityFactory::createCell('Part Number'),
WriterEntityFactory::createCell('Description'),
WriterEntityFactory::createCell('Shift'),
WriterEntityFactory::createCell('Date Production'),
WriterEntityFactory::createCell('Date Receive'),
WriterEntityFactory::createCell('Qty Transfer'),
WriterEntityFactory::createCell('Customer'),
WriterEntityFactory::createCell('PIC'),
WriterEntityFactory::createCell('Txndate'),
WriterEntityFactory::createCell('Userid'),
];
$singleRow = WriterEntityFactory::createROW($header);
$writer->addRow($singleRow);
$data = array();
// looping pembacaan Data
foreach ($get->result() as $key) {
$data_assetdata = array(
WriterEntityFactory::createCell($key->part_number),
WriterEntityFactory::createCell($key->description),
WriterEntityFactory::createCell($key->shift),
WriterEntityFactory::createCell($key->date_production),
WriterEntityFactory::createCell($key->date_receive),
WriterEntityFactory::createCell($key->qty_transfer),
WriterEntityFactory::createCell($key->id_customer),
WriterEntityFactory::createCell($key->pic),
WriterEntityFactory::createCell($key->txndate),
WriterEntityFactory::createCell($key->userid),
);
array_push($data, WriterEntityFactory::createRow($data_assetdata));
}
$writer->addRows($data);
$writer->close();
}
and this my Model
public function lihat()
{
$query = $this->db->get($this->_table);
return $query->result();
}
public function jumlah()
{
$query = $this->db->get($this->_table);
return $query->num_rows();
}
public function lihat_id($receive_id)
{
$query = $this->db->get_where($this->_table, ['receive_id' => $receive_id]);
return $query->row();
}
public function ubah($data, $receive_id)
{
$query = $this->db->set($data);
$query = $this->db->where(['receive_id' => $receive_id]);
$query = $this->db->update($this->_table);
return $query;
}
public function tambah($data)
{
return $this->db->insert($this->_table, $data);
}
public function hapus($receive_id)
{
return $this->db->delete($this->_table, ['receive_id' => $receive_id]);
}
public function getAll()
{
$this->db->from('receiving');
return $this->db->get();
}
function get_no_upload_id()
{
$q = $this->db->query("SELECT MAX(RIGHT(upload_id,2)) AS kd_max FROM receiving WHERE DATE(txndate)=CURDATE()");
$char = "-";
$kd = "";
if ($q->num_rows() > 0) {
foreach ($q->result() as $k) {
$tmp = ((int)$k->kd_max) + 1;
$kd = $char . sprintf("%02s", $tmp);
}
} else {
$kd = "1";
}
date_default_timezone_set('Asia/Jakarta');
return date('Ymd') . $kd;
}
function getSerialNumber()
{
$this->db->select('RIGHT(receiving.receive_id,5) as kode', false);
$this->db->order_by('receive_id', 'DESC');
$this->db->limit(1);
$query = $this->db->get('receiving');
if ($query->num_rows() <> 0) {
$data = $query->row();
$kode = intval($data->kode) + 1;
} else {
$kode = 1;
}
$kode_max = str_pad($kode, 4, "0", STR_PAD_LEFT);
$kode_jadi = $kode_max;
return $kode_jadi;
}
public function import_data($datareceiving)
{
$jumlah = count($datareceiving);
if ($jumlah > 0) {
// Replcae (namatable , Parameter variable upload)
$this->db->replace('receiving', $datareceiving);
}
}
public function today()
{
$today = date('ymd');
return $today;
}
public function tgl()
{
$tgl = date('d');
return $tgl;
}
public function bln()
{
$tgl = date('m');
return $tgl;
}
public function joinMasterpart()
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number','INNER');
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer','INNER');
$query = $this->db->get();
return $query->result();
}
public function joinMasterpartBarcode()
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number','INNER');
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer','INNER');
$query = $this->db->get();
return $query->result();
}
public function detail($part_number)
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number');
$this->db->where('part_number',$part_number);
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer');
$query = $this->db->get();
return $query->row();
}
and this my Html
<div id="wrapper">
<!-- load sidebar -->
<?php $this->load->view('partials/sidebar.php') ?>
<div id="content-wrapper" class="d-flex flex-column">
<div id="content" data-url="<?= base_url('incoming') ?>">
<!-- load Topbar -->
<?php $this->load->view('partials/topbar.php') ?>
<div class="container-fluid">
<div class="clearfix">
<div class="float-left">
<h1 class="h3 m-0 text-gray-800"><?= $title ?></h1>
</div>
<div class="float-right">
<i class="fa fa-file-excel"></i> Export Excel
<i class="fa fa-file-pdf"></i> Export Pdf
<i class="fa fa-plus"></i> Tambah
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#importdataketua">
<i class="fa fa-file-import"></i> Import
</button>
</div>
</div>
<hr>
<?php if ($this->session->flashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= $this->session->flashdata('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php elseif ($this->session->flashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= $this->session->flashdata('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php endif ?>
<div class="card shadow">
<div class="card-header"><strong>Receiving</strong></div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<td>Lot Number</td>
<td>Upload Id</td>
<td>Part Number</td>
<td>Description</td>
<td>Shift</td>
<td>Date Production</td>
<td>Date Receive</td>
<td>Qty Transfer</td>
<td>Pic</td>
<td>Txndate</td>
<td>Id Customer</td>
<td>Customer Name</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($all_receiving as $rows_allReceiving) { ?>
<tr>
<td>
<?= $rows_allReceiving->id_customer ?><?= $rows_allReceiving->lot_number ?>
<i class="fa fa-barcode"></i> Generate
</td>
<td><?= $rows_allReceiving->upload_id?></td>
<td>
<?= $rows_allReceiving->number_part?>
</td>
<td><?= $rows_allReceiving->description?></td>
<td><?= $rows_allReceiving->shift?></td>
<td><?= $rows_allReceiving->date_production ?></td>
<td><?= $rows_allReceiving->date_receive ?></td>
<td><?= $rows_allReceiving->qty_transfer ?></td>
<td><?= $rows_allReceiving->pic ?></td>
<td><?= $rows_allReceiving->txndate ?></td>
<td><?= $rows_allReceiving->id_customer ?></td>
<td><?= $rows_allReceiving->nama_customer ?></td>
<td>
<i class="far fa-folder"></i> Detail
<a onclick="return confirm('apakah anda yakin?')" href="<?= base_url('receiving/hapus/' . $rows_allReceiving->receive_id) ?>" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Hapus</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- load footer -->
<?php $this->load->view('partials/footer.php') ?>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="importdataketua" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Import Excel</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?= form_open_multipart('receiving/uploadexcel') ?>
<div class="form-group">
<label for="exampleFormControlFile1">Upload File</label>
<input type="file" class="form-control-file" id="exampleFormControlFile1" name="importexcel">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary"><i class="fa fa-file-import"></i> Upload</button>
</div>
<?= form_close(); ?>
</div>
</div>
</div>
<?php $this->load->view('partials/js.php') ?>
<script src="<?= base_url('sb-admin/js/demo/datatables-demo.js') ?>"></script>
<script src="<?= base_url('sb-admin') ?>/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="<?= base_url('sb-admin') ?>/vendor/datatables/dataTables.bootstrap4.min.js"></script>
<script>
function autofill() {
$.ajax({
url: 'receiving/autofillAjax',
data: 'part_number' + part_number,
}).success(function(data) {
alert('masuk');
});
}
</script>
HELP
am stuck here. I have a project that makes a table receiving with the added method using an import file with Xlsx extension ( Excel ) , they have 21 column inside table mysql and user just import file in a part. and I want it when the upload is successful. All empty data in the table is quickly filled by retrieving data from another table such as vlookup. am using Codeigniter 3.

Saving result to text file

I've searched around this site for an answer but couldn't find any help in my problem.
I have a script with a form and I'd like to get the contents of the input written into a txt file (line by line in mytext.txt file for example) when the submit button is pressed - or maybe simpler only the result.
Result / content of "echo $result['text'];" should be saved to text file (mytext.txt)
I tried to add something like that after each "echo" but it doesn't work. here is the sample code.
$f = fopen("mytext.txt", "w");
fwrite($f, $result);
fclose($f);
or
$f = fopen("mytext.txt", "w");
fwrite($f, $username);
fclose($f);
or
$txt = "$result";
$myfile = file_put_contents('mytext.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
but still no luck.
How can I do that and where to add it? With PHP or maybe with JavaScript? Help please.
edit:
PART of the script (I'm sorry I forgot about it)
<?php
if(count($check_ex) == 2){
$ex_name = $check_ex[0]."_".$check_ex[1];
}else{
$ex_name = $check_ex[0];
}
$additional_button = "<a href='javascript:void(0)' onclick='submitform_$dom_$ex_name()' ><button id='buy' class='btn btn-success btn-xs pull-right order-btn'>".__($additional_button_name, 'kate')."</button></a>";
}elseif($integration == 'woocommerce'){
if($show_price){
$show_price = '- '.kate_display_price($username).__('/year','kate');
}
$additional_button = "<a href='?&add-to-cart=$additional_button_link&username=$username' id='buy' class='btn btn-success btn-xs pull-right order-btn' $buy_new_tab >".__($additional_button_name,'kate')." $show_price</a>";
}elseif($integration == 'custom'){
if(!$additional_button_name == '' AND !$additional_button_link == ''){
$additional_button_links = str_replace( '{username}', $username, $additional_button_link );
$additional_button = "<a id='buy' class='btn btn-success btn-xs pull-right order-btn' href='$additional_button_links' $buy_new_tab >".__($additional_button_name,'kate')."</a>";
}else{
$additional_button = '';
}
}else{
$additional_button = '';
}
$custom_not_found_result_text = str_replace( '{username}', $username, $custom_not_found_result_texts );
$whmcs = "<script type='text/javascript'>
function submitform_$dom_$ex_name()
{
document.whmcs_$dom_$ex_name.submit();
}
</script>
<form method='post' name='whmcs_$dom_$ex_name' id='whmcs' action='$additional_button_link/cart.php?a=add&username=register' $buy_new_tab>
<input type='hidden' name='usernames[]' value='$username' >
<input type='hidden' name='usernamesregperiod[$username]' value='1'>
</form>";
if ($available->status == 1) {
$result = array('status'=>1,
'username'=>$username,
'text'=> '<div class="callout callout-success alert-success clearfix available">
<div class="col-xs-10" style="padding-left:1px;text-align:left;">
<i class="glyphicon glyphicon-ok" style="margin-right:1px;"></i> '.__($custom_found_result_text,'kate').' </div>
<div class="col-xs-2" style="padding-right:1px">'.__($additional_button,'kate').' '.$whmcs.'</div>
</div>
');
echo $result['text'];
} elseif($available->status == 0) {
$result = array('status'=>0,
'username'=>$username,
'text'=> '<div class="callout callout-danger alert-danger clearfix not-available">
<div class="col-xs-10" style="padding-left:1px;text-align:left;">
<i class="glyphicon glyphicon-remove" style="margin-right:1px;"></i> '.__($custom_not_found_result_text, 'kate').'
</div>
<div class="col-xs-2" style="padding-right:1px">'.$www_link.'</div>
</div>
');
echo $result['text'];
}elseif ($available->status == 2) {
$result = array('status'=>2,
'username'=> $username,
'text'=> '<div class="callout callout-warning alert-warning clearfix notfound">
<div class="col-xs-10" style="padding-left:1px;text-align:left;">
<i class="glyphicon glyphicon-exclamation-sign" style="margin-right:1px;"></i> '.__('not found','kate').'
</div>
</div>
');
echo $result['text'];
}
}
}
else
{
echo 'Please enter the username';
}
}
If you are having errors when trying to get this code to run, check that you have granted your PHP file access to write information to the hard drive.
The code is correct, it may be that the directory does not have permission to create files.
You must check if the directory you're trying to save your txt file is writable.
Example:
$contents = 'Here goes your content';
$dirName = __DIR__; //in case you're saving in another directory, you may use 'files/directory/' instead of __DIR__
$fileName = $dirName.'/mytext.txt';
if (!is_writable($dirName)) {
throw new \Exception("This folder is not writable: '$dirName'");
}
//Checks if the content was added
if (!file_put_contents($fileName, $contents)) {
throw new \Exception("Could not write to file: $fileName");
}

uploading file not working in codeigniter 3 error: you did not select any file

i have created the root directory and set its path, i done the front end as was. the ide is not giving any error but when i proceed it say you did not select any image.
the controller code:
class Images extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->data['displayname'] = $this->admin->lastname;
$this->data['images'] = Image::all();
$this->data['btn'] = 'Save';
$this->data['content'] = 'admin/images/index';
$this->load->view('layouts/admin', $this->data);
}
public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
//$config['max_size'] = 100;
//$config['max_width'] = 1024;
//$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('images'))
{
$error = array('error' => $this->upload->display_errors());
// echo $this->upload->display_errors();
$this->load->view('index', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
the view code:this is the form for choosing the file
<?= form_open('admin/images/do_upload') ?>
<label><?= form_upload('images[]')?></label>
<div class="input-group-btn">
<button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
</div>
</div>
</ul>
<div class="line"></div>
<?= form_submit('', 'Submit', 'class="publish-btn"') ?>
<?= form_close()?>
<?= form_open_multipart('admin/images/do_upload') ?>
Use the above code instead of
<?= form_open('admin/images/do_upload') ?>
i added the multipart to my form which created an issue of invalid path which i solved by initializing the library after adding
$this->upload->initialize($config);
after this line of loading the library.
$this->load->library('upload', $config);
first load the library then initialize.
but still the problem of an selection is not solved
i tried a couple of other codes too.
well after a lot of research and trying lots of codes and i solved my issue
here's the full thing
the controller code:
public function create($id)
{
$config ['upload_path'] = 'uploads';
$config ['allowed_types'] = 'gif|jpg|png';
$config ['encrypt_name'] = TRUE;
$this->upload->initialize($config);
$package = Package::find($id);
$files = $_FILES;
$cpt = count($_FILES ['images'] ['name']);
for ($i = 0; $i < $cpt; $i++) {
$_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
$_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
$_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
$_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
$_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];
if ($this->upload->do_upload('images')){
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
$package->create_images(array('image_location' => $file_name));
}
}
redirect('admin/packages/');
}
}
the view code:
<div class="container">
<?= form_open_multipart('admin/images/create/' . $this->uri->segment(4)) ?>
<div class="row">
<div class="col-md-8 publish">
<h4>Image Gallery</h4>
<div class="line"></div>
<ul>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<div class="input-group control-group after-add-image">
<label><input type="file" name="images[]"></label>
<div class="input-group-btn">
<button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
</div>
</div>
</ul>
<div class="line"></div>
<?= form_submit('', 'Submit', 'class="publish-btn"') ?>
<?= form_close()?>
<div class="clear-all"></div>
<!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,-->
<div class="copy-field" style="display: none">
<div class="control-group input-group" style="margin-top:10px">
<label><label><input type="file" name="images[]"></label></label>
<div class="input-group-btn">
<button class="btn btn-danger delete" type="button"><i class="glyphicon glyphicon-delete"></i> Remove</button>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
//here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
$(".add-image").click(function(){
var html = $(".copy-field").html();
$(".after-add-image").after(html);
});
//here it will remove the current value of the remove button which has been pressed
$("body").on("click",".delete",function(){
$(this).parents(".control-group").remove();
});
});
</script>
its getting all the images dynamically, uploading them to the directory and then stores the path to the database
done!
the image for front end
In file uploading case you should use
<?php form_open_multipart('admin/images/do_upload') ?>
Not this
<?php form_open('admin/images/do_upload') ?>

Slider inside modal, modal dissappear when clicking next

So, I am making a slideshow inside a modal. The idea is when user clicks "Slideshow", a modal will popup showing a slideshow of images. However when I click next button to view the next image, the modal suddenly closes. I tried putting the code to disable any external or button clicks but it still closes.
here is the code:
<button type="button" id="slide" class="btn btn-primary" data-toggle="modal" data-target="#mySlider">Persembahan Slaid</button><br><br><br>
<div class="modal fade" id="mySlider" tabindex="-1" role="dialog" aria-labelledby="mySliderLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Tutup</span></button>
<h4 class="modal-title" id="mySliderLabel"><?php echo $title?></h4>
</div>
<div class="modal-body">
<form ACTION="" method = "POST" enctype="multipart/form-data">
<div class="form-group">
<div class="w3-content w3-display-container">
<?php
$sql = "SELECT * FROM storytelling WHERE title = '$title' ORDER BY id";
$result = mysqli_query($db, $sql);
while($row = $result -> fetch_array())
{
?>
<div class="w3-display-container mySlides">
<?php echo "<img src = 'images/".$row['image']."' style='width:100%'>"; ?>
<div class="w3-display-bottomright w3-large w3-container w3-padding-16 w3-black">
<?php echo $row['text']?>
</div>
</div>
<?php
}
?>
<button class="w3-button w3-display-left w3-black" onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-display-right w3-black" onclick="plusDivs(1)">❯</button>
<script>
$(document).ready(function() {
$(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
});
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
<?php if(isset($_POST['save']))
{
//target folder to keep the media
$target = "images/".basename($_FILES['image']['name']);
//get all submitted data from form
$image = $_FILES['image']['name'];
$text = $_POST['text'];
if(!empty($_FILES['image']['name']))
{
$sql = "INSERT INTO storytelling(title, image, text ) VALUES ('$title', '$image', '$text')";
$result=mysqli_query($db, $sql);
if($result){
$message = "Cerita akan ditambah selepas diluluskan admin";
echo "<script type='text/javascript'>alert('$message');</script>";
header("Refresh:0");
} else {
$message = "Cerita gagal ditambah";
echo "<script type='text/javascript'>alert('$message');</script>";
}
move_uploaded_file($_FILES['image']['tmp_name'], $target);
echo "<script type='text/javascript'>location.href='?title=$title';</script>";
}
else
{
$message = "Sila pilih semua fail";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
?>
</div>
</form>
</div>
</div>
</div>
</div>
May I know how to view the next image in the modal without it closing ?
Thank you.

compress and image upload in to a table without store image in upload folder using codeigniter

Compress and image upload in to a database table without store image in upload folder using codeigniter. I am not getting any error, but images are not inserted in to a table. Any mistake? Please suggest me.
Controller
public function buyer_profile_image() {
$file_type = $_FILES['image']['type'];
$allowed = array("image/jpeg", "image/gif", "image/png");
if (!in_array($file_type, $allowed)) {
$this->load->view('buyerprofile');
} else {
$source_img = $_FILES['image']['tmp_name'];
$destination_img = 'destination .jpg';
$d = $this->compress($source_img, $destination_img, 50);
$image = addslashes($d);
$image = file_get_contents($image);
$image = base64_encode($image);
if ($image == "") {
$_SESSION["errmsg"] = "please select image to post";
$this->load->view('buyerprofile');
} else {
$data = array(
'profile_image' => $image,
);
$this->Profile_model->Product_insert($data);
$this->load->view('buyerprofile');
}
}
}
model
public function Product_insert($data){
$this->db->insert('siddu',$data);
view page
<form action="<?php echo base_url(); ?>Index.php/Profile_cntrl/buyer_profile_image" method="post" enctype="multipart/form-data">
<div class="text-center profile-bg">
<div class="user-bg"></div>
<a href="#" class="user-img">
<img src="<?php echo base_url(); ?>images/prasanthi.jpg" class="img-circle img-user" alt="" width="100px;" height="100px;"/>
</a>
<div class="user-info">
<span class="">xxxxxxx</span>
<div class="user-location">
<i class="fa fa-map-marker"></i> Bangalore
</div>
</div>
<div class="change-profile">
<!--<span data-role="upload" class="upload-trigger"><i class="fa fa-plus"></i> Change Profile</span>-->
<div class="attachment">
<input type="file" name="image" id="image"/>
</div>
<input type="submit" value="upload" class="btn btn-success" style="width:70px;">
</div>
</div>
</form>

Categories