How to Set or retrieve old Path image when we not update the image in the form multiple images in Codeigniter 2.2.6 - codeigniter-2

I have edit form in codeigniter in that form i have 15 more image file while i update the image it updating in database but even am not update the images in the form it goes and save as null or empty path .But i need solution for that when am not update all 15 files should retrive the same old image path which it is stored in database.Please Could you guys give better solution for this.
My Edit Form
controller:
if($this->input->post('submit'))
{
if($_FILES['file']['name']!='')
{
$filename = $_FILES['file']['name'];
$file_name1 = "upload_".$this->get_random_name()."_".$filename;
$_SESSION['file_upload']=$file_name1;
$file ="uploads/images/".$file_name1;
}
if($_FILES['file1']['name']!='')
{
$filename = $_FILES['file1']['name'];
$file_name2 = "upload_".$this->get_random_name()."_".$filename;
$_SESSION['file_upload']=$file_name2;
$file ="uploads/images/".$file_name2;
}
$query = $this->scener_model->popular_upload($file_name1,$file_name2)
}

If your is empty then pass hidden input value or else pass newly uploaded value like this..
if(!empty($_FILES()){
//your uploaded value here
} else {
//hidden attribute value
}

if($this->input->post('submit1')){
$titlemain = $this->input->post('title_main');
$price = $this->input->post('price');
$package = $this->input->post('package');
$titleinner = $this->input->post('title_inner');
$city_package = $this->input->post('city_packge');
if(!empty($count =count($_FILES['file1']['name']))){;
for($i=0; $i<$count;$i++){
$filename1=$_FILES['file1']['name'][$i];
//print_r($filename);exit;
$filetmp=$_FILES['file1']['tmp_name'][$i];
$filetype=$_FILES['file1']['type'][$i];
$images = $_FILES['file1']['name'];
$filepath="uploads/images/".$filename1;
move_uploaded_file($filetmp,$filepath);
}
$filename1 = implode(',',$images);
}
else{
$filename1=$this->input->get('iti_image2') ;
//print_r( $data['newz1']);exit;
}
my view page:
<div class="col-sm-8">
<input type="button" id="get_file" value="Grab file">
<?php
$imss= $result->iti_image2;
?>
<input type="file" id="my_file" name="file3[]" value="<?php echo $imss ?>" multiple/>
<div id="customfileupload">Select a file</div>
<input type="hidden" class="btn btn info" id="image" name="iti_image2" accept="image" value="<?php echo $result->iti_image2; ?>" multiple/ >
</div>
<script>
document.getElementById('get_file').onclick = function() {
document.getElementById('my_file').click();
};
$('input[type=file]').change(function (e) {
$('#customfileupload').html($(this).val());
});
</script>
</div>
my Model:
function itinerary_updte($filename4,$filename5){
$update_itinerarys = array(
'iti_image2' =>$filename4,
'iti_image3' =>$filename5
);
$this->db->where('id', $id);
$result = $this->db->update('sg_itinerary', $update_itinerarys);
return $result;
}

Finally guys i found a solution for image updating follwing some tutorials see the link
"http://www.2my4edge.com/2016/04/multiple-image-upload-with-view-edit.html"
thanks buddies who are give the logic and commenting on my post and thanks alot #ankit singh #Lll

Related

$_FILES['imagem'] is undefined in Firefox

My website is built using Codeigniter, and there's an area for users to modify their information. This area allows users to choose a profile picture, and when editing it, the selected picture is previewed. In case they don't choose a new one, there's a hidden field storing its name, which is passed to the controller to specify the same image name, but if the user decides to change it, the new name is passed to the controller.
public function edit($id)
{
$this->input->post('tipo_usuario') === 'F' ? $validator = 'editar_pessoa_fisica' : $validator = 'editar_pessoa_juridica';
if ($this->form_validation->run($validator)) {
$data = array();
$data['nome_razao_social'] = $this->input->post('nome_razao_social');
$data['nome_responsavel'] = $this->input->post('nome_responsavel');
$data['nome_fantasia'] = $this->input->post('nome_fantasia');
$data['cpf_cnpj'] = $this->input->post('cpf_cnpj');
$data['telefone'] = $this->input->post('telefone');
$data['telefone_2'] = $this->input->post('telefone_2');
$data['email'] = $this->input->post('email');
$data['novo_email'] = $this->input->post('novo_email');
$data['senha'] = md5($this->input->post('senha'));
$data['cep'] = $this->input->post('cep');
$data['logradouro'] = $this->input->post('logradouro');
$data['id_cidade'] = $this->input->post('id_cidade');
$data['id_estado'] = $this->input->post('id_estado');
$data['numero'] = $this->input->post('numero');
$data['complemento'] = $this->input->post('complemento');
$data['tipo_usuario'] = $this->input->post('tipo_usuario');
/*
HERE IS IN CASE THE USER DOES NOT CHANGE HIS PROFILE PICTURE
*/
$data['imagem'] = $this->input->post('imagem_old');
$data['url'] = $this->input->post('url');
// Nova senha?
if ($this->input->post('novasenha') !== '') {
$data['senha'] = md5($this->input->post('novasenha'));
} else {
$data['senha'] = $this->input->post('senha');
}
/*
HERE IS IN CASE THE USER CHANGES HIS PROFILE PICTURE
*/
// Nova imagem?
if ($_FILES['imagem']['name'] !== '') {
$data['imagem'] = $_FILES['imagem']['name'];
}
// Novo e-mail?
if ($this->input->post('email') !== $this->input->post('novoemail')) {
$data['novo_email'] = $this->input->post('novoemail');
$this->Usuarios_model->update($data, $id);
$this->Usuarios_model->send_confirmation_email($data['novo_email'], $data['email']);
}
if ($this->input->post('novo_novo_email') !== $this->input->post('novo_email')) {
$data['novo_email'] = $this->input->post('novo_novo_email');
$this->Usuarios_model->update($data, $id);
$this->Usuarios_model->send_confirmation_email($data['novo_email'], $data['email']);
}
if ($this->Usuarios_model->update($data, $id)) {
$this->upload->do_upload('imagem');
$this->session->set_flashdata('message', 'Dados alterados');
echo json_encode(array(
'redirect' => '/usuario/painel'
));
}
} else {
echo json_encode(array(
'type' => 'validation',
'message' => validation_errors(),
));
}
}
This is the HTML:
<form action="/auto/usuario/edit/<?php echo $id_usuario; ?>" method="POST" class="formulario" enctype="multipart/form-data">
<input type="hidden" name="tipo_usuario" value="F"/>
<div class="p100">
<span class="titulo">Foto de Perfil</span>
<div class="imagem_destaque img_perfil image-trigger">
<div class="file-upload-trigger">
<input type="file" name="imagem" class="none file-chooser"/>
<img src="/uploads/perfil/<?php echo $u['imagem'] ?>" class="preview more"/>
</div>
</div>
<input type="hidden" name="imagem_old" value="<?php echo $u['imagem']; ?>"/>
</div>
With Google Chrome, it works fine, but in Firefox 45, if I do not choose a new image, an error is thrown:
Severity: Notice
Message: Undefined index: imagem
Filename: controllers/Usuario.php
Line Number: 362
It only works locally.
If you do not upload a new image, your $_FILES[] is undefined, as the error says. To check if the user has changed his image you should do:
if ( isset($_FILES['imagem']['name']) ) {
$data['imagem'] = $_FILES['imagem']['name'];
}

How to image update using laravel5

I don't know how to edit image using laravel5. When I update my image file It show this error:
FatalErrorException in SiteadminController.php line 1719:
Class 'App\Http\Controllers\Image' not found
Controller
public function siteadmin_update_ads(Request $request)
{
$post = $request->all();
$cid=$post['id'];
// $img=$post['ads_image'];
$v=validator::make($request->all(),
[
'ads_title'=>'required',
'ads_url' => 'required',
]
);
if($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
//$image = Image::find($cid);
else
{
$image = Image::find($cid);
if($request->hasFile('ads_image'))
{
$file = $request->file('ads_image');
$destination_path = '../assets/adsimage/';
$filename = str_random(6).'_'.$file->getClientOriginalName();
$file->move($destination_path, $filename);
$image->file = $destination_path . $filename;
$data=array(
'ads_title'=>$post['ads_title'],
'ads_url'=>$post['ads_url'],
'ads_image'=>$post['ads_image'],
);
}
// $image->caption = $request->input('caption');
// $image->description = $request->input('description');
$image->save();
}
// $i = DB::table('le_color')->where('id',$post['id'])->update($data);
$i=Ads_model::update_ads($data,$cid);
if($i>0)
{
Session::flash ('message_update', 'Record Updated Successfully');
return redirect('siteadmin_manageads');
}
else {
return Redirect('siteadmin_editads');
}
}
Model
public static function update_ads($data,$cid)
{
return DB::table('le_ads')->where('id',$cid)->update($data);
}
View
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Upload Image*</label>
<div class="col-md-9 col-sm-6 col-xs-12">
<input type='file' id="field" class='demo left' name='ads_image' data-type='image' data-max-size='2mb'/><br>
<img src="{{ url('../assets/adsimage/').'/'.$row->ads_image}}" style="height:90px;">
</div>
</div>
I don't know what is that Image, so I am at least possible help to you. But I'll try to solve it.
What you can do is:
Add backslash \ before the Image. It should look like this: \Image::find($cid);
Or else, it is a Intervention package: you need to import the Facade of Intervention Package.
add use Intervention\Image\Facades\Image;
I hope this helps you out.
you are missing the 'use' import statement for class image so its trying to find the class in the current namespace which is wrong assuming your model is stored at App namespace then add the below in the begining of controller
use App\Image

CodeIgniter - I can't update row in my table

I can't find the correct way update one row in my table.
My view:
...
<?php echo form_open('ImenikController/verify_editing_phonebook/'.$this->uri->segment(3)); ?>
Ime i prezime*:
<input type='text' name='ime_prezime' value=""> <br><br>
Ulica i broj: <input type='text' name='ulica' value=""> <br><br>
Mesto: <input type='text' name='mesto' value=""> <br><br>
Telefon*: <input type='text' name='telefon' value=""> <br><br>
<u>Napomena: Polja sa zvezdicom su obavezna.</u> <br /> <br />
<input background:url('images/login-btn.png') no-repeat; border: none;
width='103' height='42' style='margin-left:90px;' type='submit' value='Izmeni'>
<?php echo form_close(); ?>
...
My Controller:
function verify_editing_phonebook()
{
if ($this->session->userdata('logged_in'))
{
if ($this->session->userdata('admin') == 1)
{
$this->form_validation->set_rules('ime_prezime', 'Ime i prezime', 'trim|required|xss_clean');
$this->form_validation->set_rules('telefon', 'Telefon', 'trim|required|xss_clean');
if ($this->form_validation->run() == TRUE)
{
$id = $this->uri->segment(3);
if (isset($id) and $id > 0)
{
$this->load->model('LoginModel');
$this->LoginModel->edit_phonebook($id);
redirect(site_url().'ImenikController/', 'refresh');
}
}
else {
$temp = $this->session->userdata('logged_in');
$obj['id'] = $temp['id'];
$data['records'] = $this->LoginModel->get_Username($obj);
$this->load->view('ErrorEditing', $data);
}
}
else {
$this->load->view('restricted_admin');
}
}
else {
$this->load->view('restricted');
}
}
My Model:
function edit_phonebook($id)
{
$data = array ('ime_prezime' => $this->input->post('ime_prezime'),
'ulica' => $this->input->post('ulica'),
'mesto' => $this->input->post('mesto'),
'telefon' => $this->input->post('telefon'));
$this->db->where('id', $id);
$this->db->update('pregled', $data);
}
That solution doesn't work.
I get the url: localhost/imenik114/ImenikController/verify_editing_phonebook
It is a blank (white) page. And not editing row in table.
Basic Debugging Strategies
(1) Have you created all the view files?
(2) Have you tested edit_phonebook($id) independently?
(3) What does redirect(site_url().'ImenikController/', 'refresh'); display?
Did you define the index function for ImenikController?
(4) What URL did you use when you say 'That solution doesn't work.' ?
(5) If your URL is: "localhost/imenik114/ImenikController/verify_editing_phonebook"
you did not type in id in your 3rd segment
(6) If you are not logged in, do you see the correct restricted view?
(7) If you are logged in and NOT admin, do you see the correct restricted_admin view?
Potential Bug
Looking at this part of your code:
if ($this->form_validation->run() == TRUE)
{
$id = $this->uri->segment(3);
if (isset($id) and $id > 0)
{
$this->load->model('LoginModel');
$this->LoginModel->edit_phonebook($id);
redirect(site_url().'ImenikController/', 'refresh');
}
// You need to handle the case of $id not set
else
{
// load a view with error page saying $id is missing...
}
}
if your form validates, and you don't pass in segment(3), your controller will not load a view, therefore, you will get a blank page.
You need to check the case of $id not present, see code.
Code Fix
One more detail: the statement $id = $this->uri->segment(3); will set $id either to the id number or FALSE, therefore, you don't need isset($id) in your if statement. I would write $id = $this->uri->segment(3,0); to set the default to 0 instead of FALSE to keep the logic a bit clearer.
Thanks for answer but I solved my problem somehow.
I made a link in my view:
Edit
And in view for editing:
<?php echo form_open('Controller/verify_editing_phonebook/'.$this->uri->segment(3)); ?>
Function verify_editing_phonebook passed trough validation and loading view.
Thanks once again and sorry for my English...

Joomla Pagination URL is excluding the view=viewname

I have pagination setup on a custom Joomla component. To avoid a page long explanation, we're kind of doing some intricate iframe embedding and forward masking. This is pagination for the front end of the component.
In my iframe, I have a list of puppies (from the custom component). It is paginated. In order for the puppies to display correctly in the iframe it has to have the URL :
http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-2.html?tmpl=component&view=microsite
However when I actually click on the pagination link for page 2 it drops the view=microsite which causes problems. How can I adjust this so that it does not drop the view=microsite?
The original URL is http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-1.html?tmpl=component&view=microsite
The code for this pagination is long and between the model, view and view.html.php so it seems difficult for me to post all the related code. Here's some though where I have been looking.
Any ideas or hints on where / how to do this?
Thanks
Zach
// Get the pagination request variables
$limit = $app->input->get('limit', $params->get('display_num', 20), 'uint');
$limitstart = $app->input->get('limitstart', 0, 'uint');
$this->setState('puppies.limit', $limit);
$this->setState('puppies.limitstart', $limitstart);
// Load the parameters.
$this->setState('params', $params);
}
/** Method to get a store id based on the model configuration state. **/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('puppies.breed_alias');
$id .= ':' . $this->getState('puppies.limit');
$id .= ':' . $this->getState('puppies.limitstart');
$id .= ':' . serialize($this->getState('puppies.filter'));
$id .= ':' . $this->getState('puppies.featured');
return parent::getStoreId($id);
}
/** Method to get a JPagination object for the data set. **/
public function getPagination()
{
// Create the pagination object.
$limit = (int) $this->getState('puppies.limit');
$page = new JPagination($this->getTotal(), $this->getStart(), $limit);
return $page;
}
/** Method to get the total number of items for the data set. **/
public function getTotal()
{
return $this->items_total;
}
/** Method to get the starting number of items for the data set. **/
public function getStart()
{
$start = $this->getState('puppies.limitstart');
$limit = $this->getState('puppies.limit');
$total = $this->getTotal();
if ($start > $total - $limit)
{
$start = max(0, (int) (ceil($total / $limit) - 1) * $limit);
}
return $start;
}
Again, a portion of the code here but I have no idea what to begin posting for an answer to this so please I will post any code but point me in the right direction, thanks.
Somewhere at the bottom of your "adminform" in that view, there should be the all the hidden inputs that submit the view / controller / token.
Something like this:
<input type="hidden" name="option" value="com_puppies" />
<input type="hidden" name="view" value="microsite" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<inupt type="hidden" name="controller" value="microsite" />
<input type="hidden" name="filter_order" value="<?php echo $this->escape($this->state->get('list.ordering')); ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->escape($this->state->get('list.direction')) ?>" />
<?php echo JHtml::_('form.token'); ?>
Feel free to remove the inputs you won't use (i.e the filter_order ones if you handle that differently). The vital one is the view input. Also, leave the controller input out if you are not using a controller for that view (meaning you are using the default controller for that component)
Can you give this link http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-1.html?tmpl=component&view=microsite without SEF? you can try to create file /templates/{$your_template}/html/pagination.php with such code
<?php
function pagination_item_active(&$item){
$getData = new JInput($_GET);
$view = $getData->get('view','','string');
$link_part = ($view == 'microsite' ? '&view=microsite' : '');
$link = "<a title=\"" . $item->text . "\" href=\"" . $item->link.$link_part . "\" class=\"pagenav2\">" . $item->text . "</a>";
return $link;
}
function pagination_item_inactive(&$item){
return "<span class=\"pagenav\">" . $item->text . "</span>";
}
Also i think your problem in incorrect link. How you got this link http://americasfavoritepuppybreeders.com/puppies/breed/labrador/page-1.html?tmpl=component&view=microsite? If you use ready link with view=microsite, try create link on your view (microsite) in admin panel and use this link.

how to echo the database contents in codeigniter while editing

How do i get the form field contents while editing (updating) entries in database ?
my controler is
//edit sidebar contents
function edit_lsidebar(){
if(isset($_POST['heading'])){
//adding text fields
$heading = $this->input->post('heading');
$content_text = $this->input->post('content_text');
$url = $this->input->post('url');
$link_text = $this->input->post('link_text');
$this->Lside_bar_model->edit_lsidebar($heading, $content_text, $url, $link_text);
redirect('welcome');
}
else $this->load->view('edit_lside_bar', $data);
}
my model is
function edit_lsidebar($heading, $content_text, $url, $link_text){
$data = array(
'heading'=>$heading,
'content_text'=>$content_text,
'url'=> $url,
'link_text' => $link_text
);
$this->db->where('id',$this->uri->segment(3));
$this->db->update('lsidebar', $data);
}
please help
When loading your edit_lside_bar view pass the existing $heading, $content_text, $url, $link_text variables with the data array you're passing to the view.
Then inside the view echo those values as a value attribute for input fields. For example:
Inside your controller:
else {
$data["lside_bar"] = $this->Lside_bar_model->get_lside_bar($id);
$this->load->view('edit_lside_bar', $data);
}
Inside your view:
<input type="text" name="heading" value="<?php echo $lside_bar->heading; ?>" />
<textarea name="content_text"><?php echo $lside_bar->content_text; ?></textarea>
....
That should give you a nice push in the right direction. Hope that helps!

Resources