I want stored image delete when Updated with new image

delete previous image from folder when updated by new image in laravel
delete previous image from folder when updated by new image in php
php upload and replace image in directory and update db
laravel delete image from storage folder
delete image from folder using javascript
delete image from folder in php
delete image from folder in laravel
delete image from database and folder in php

I am new to codeigniter and I am having problem in edit item image, not that it don't get update as it do but there are too many images in the upload folder directory.

What I want to do is I want the previously stored image to be deleted in the upload directory when I update new image.

Here is my controller:

function edit($shop_id = null){

        if ( ! $this->ion_auth->logged_in() OR ! $this->ion_auth->is_admin())
        {
            redirect('auth', 'refresh');
        }
        /* Breadcrumbs */
        $this->data['breadcrumb'] = $this->breadcrumbs->show();

        /* Variables */
        $tables = $this->config->item('tables', 'ion_auth');

        $this->data['shop_id']   = $shop_id;
        /* Get all category */          
        $this->data['shopInfo'] = $this->shop_model->getShopInfo($shop_id);
        //echo "<pre>";print_r( $this->data['shopInfo']);echo "</pre>";exit;

        /* Validate form input */
        $this->form_validation->set_rules('shop_name', 'Shop Name', 'trim|required'); 
        $this->form_validation->set_rules('shop_latidude', 'Shop Latidude', 'trim|required'); 
        $this->form_validation->set_rules('shop_longitude', 'Shop Longitude', 'trim|required');   



        if($this->form_validation->run() == true) {
            $config['upload_path'] =  './assets/uploads/shop/';
            //die(var_dump(is_dir($config['upload_path'])));
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '1024';
            $config['overwrite'] = TRUE;

            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            $img = "logo";

            $img_upload = $this->upload->do_upload($img);
            $data  = $this->upload->data();
            $file  = array('file_name' => $data['file_name'] );           
            $data  = array('upload_data' => $this->upload->data());
            $photo = base_url().'assets/uploads/shop/'.$file['file_name'];

            if($img_upload == 1 ) $post_photo = $photo;
            else $post_photo = $this->input->post('hidden_photo');

            if($this->input->post('status')){
                $status = 1;
            }else{
                $status = 0;
            }
            $shopInfo = array(
                    'shop_name'     =>  $this->input->post('shop_name'),
                    'merchant_id'   =>  $this->input->post('merchant_id'),
                    'photo'         =>  $post_photo,
                    'description'   =>  $this->input->post('shop_desc'),
                    'registered_date'=> date('Y-m-d H:i:s'),
                    'is_active'     =>  1,
                    'shop_location' =>  $this->input->post('shop_loc'),
                    'shop_address'  =>  $this->input->post('shop_add'),
                    'shop_phone'    =>  $this->input->post('shop_ph'),
                    'shop_latitude' =>  $this->input->post('shop_latidude'),
                    'shop_longitude'=>  $this->input->post('shop_longitude'),
                    'open_hour' => $this->input->post('open_hour'),
                    'close_hour' => $this->input->post('close_hour'),
                    'remark' => $this->input->post('remark'),
                    'approved' => $status
                );

            $this->shop_model->shopUpdate($shop_id, $shopInfo);

            redirect(base_url() . 'admin/shop', 'refresh');

        } else {

            $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
            /* Load Template */
            $this->data['merchant'] = $this->merchant_model->getAllMerchants();
            $this->template->admin_render("admin/shop/edit", $this->data);
        }

    }

Here is my Model:

function shopUpdate($shop_id, $shopInfo) {
        $this->db->where('shop_id', $shop_id);
        if($shopInfo) {
            $query = $this->db->update('shop', $shopInfo);
            if ($query) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

 function shopUpdate($shop_id, $shopInfo) {
     $q = $this->db->select('photo')->where('shop_id', $shop_id)->get('shop');
       if ($q->num_rows() > 0) {
        $imgName = $q->row();
// image path must be './admin/shop'
            unlink("./{image pathe}/".$imgName);
       } 

       $this->db->where('shop_id', $shop_id);
        if($shopInfo) {
            $query = $this->db->update('shop', $shopInfo);
            if ($query) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }    
    }

you got file name when image got uploaded so get the file name where you are going to update and delete file first. Use unlink to delete file. run update query. you just need to change in model for updating and deleting at same time.

I want to delete the stored image while update new image, You can write this. This will solve your problem public function update($id) { $​users = AdminLogin::find($id); if(Input::hasFile('image_file'))  Bottom Line. Reading here, you should know more information about how to delete old backups in Windows 10/8/7. To delete Windows image backup automatically to manage Windows backup disk space, MiniTool ShadowMaker is strongly recommended here.


First, check if new image uploading or not

$new_image = $_FILES['userfile']['name'] ? $_FILES['userfile']['name'] : '';
if($new_image != ''){
    $old_image = $this->shop_model->getOlgImage($shop_id);
    if(isset($old_image) && file_exists('image-path/photo.jpg')){
        unlink('image-path/image');
    }
}

Old image is now deleted. Upload new

$config['upload_path'] =  './assets/uploads/shop/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '1024';
$config['overwrite'] = TRUE;

$this->load->library('upload', $config);
$this->upload->initialize($config);
$img = "logo";

Give name of your input type file name to $this->upload->do_upload() not variable

No need to add $this->upload->data() twice

if($this->upload->do_upload('userfile')){

$data  = $this->upload->data();
$photo = base_url().'assets/uploads/shop/'.$data['file_name'];

$post_photo = $photo;
} else $post_photo = $this->input->post('hidden_photo');

if($this->input->post('status')){
    $status = 1;
}else{
    $status = 0;
}

Get old image

public function getOldImage($shop_id){
    return $this->db->get_where('shop', ['shop_id' => $shop_id])->row()->photo;
}

I want to delete the stored image while update new image, I want to delete the stored image while update new image , i has trying this method (unlink) but nothing change , is there any other way ? public  If you’re a typical home user looking to back up your files, you probably don’t need to create a system image. How to Create and Restore System Images To create a system image on Windows 8.1, open the Control Panel, navigate to System and Security > File History, and click the System Image Backup link at the bottom-left corner of the window.


First, you need to get image name from the database by ID then update record. Once the record is updated then you can delete that image the folder directory.

function shopUpdate($shop_id, $shopInfo) {
       //fetch image name from the database by shop_id
       $imageName = $this->db->select('photo')->where('shop_id', $shop_id)->get('shop');

        $this->db->where('shop_id', $shop_id);
        if($shopInfo) {
            $query = $this->db->update('shop', $shopInfo);
            if ($query) {
             //record is updated successfully now delete that image from folder
             if ($imageName->num_rows() > 0) {              
                unlink("./{image pathe}/".$imageName->row());
              } 

                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

unlink()

Delete previous image from folder when updated by new image, How can i delete the previous image from folder when it is update by new image. my current image update function is like this public function update( 4: Click/tap on System Image Backup. 5: Click/tap on the Create a System Image link on the left side. 6: Windows will quickly search for available backup devices. 7: Select the location you want to save your system image to. 8: At this point you can select any available drives you would like to be included in the backup.


Practical Database Programming With Visual C#.NET, Text; //reserve the new inserted faculty photo location if (FacultyImage == string. the updated faculty name stored in the textbox control txtName. image file is empty, which means that the user did not want to insert a new faculty image with this NET Web Application to Update and Delete Data in Oracle Databases 709. If the image you want to remove is covered in our Removal Policies, ask Google to remove the image from Google search results. Learn more about removing "revenge porn" from Google search results . If you believe the image should be removed from Google's search results for legal reasons, visit the legal removals page.


Absolute Beginner's Guide to Microsoft Windows Vista, To remove an account password you must also provide the account's current password. When you type a new password into Internet Explorer it asks whether you want it to If you click Yes, the password is stored with your account​. from a new location, open the folder that contains the image (refer to Figure 16.6),  Delete the old image set ; Recreate one with a different name and add your splash screen images; Update your storyboard to use this 'new' image set reference; It will update for sure ! (I even tested with app already installed on the device). No need to clean cache of device or so.


How to delete images from the gallery but keep the copy in a folder , But the pictures still stored in phone-memory will take storage and incidentally you need to use the Free-up space option in the Google Photos  When you upgrade Configuration Manager 2012 to current branch, the site regenerates the default boot images. This update includes the new WinPE version from the updated Windows ADK and the new version of the Configuration Manager client. All boot image customizations remain unchanged. The site doesn't modify custom boot images.