SlideShare une entreprise Scribd logo
1  sur  21
View/add/edit/delete images in
CodeIgniter
application/config/routes.php
$route['default_controller'] =
'MainController/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
application/config/autoload.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('form');
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter2/
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
/config/database.php
db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'images',
'dbdriver' => 'mysqli',
'dbprefix' => '',
………………………………………..
MainController.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MainController extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('MainModel','f');
}
public function index()
{
$this->load->view('view');
}
public function view($id=NULL){
$row=$this->f->getImage($id);
$data['r']=$row;
$this->load->view('view_single',$data);
}
public function upload()
{
$this->load->helper('form');
$this->load->view('upload');
}
public function save()
{
$url=$this->do_upload();
$title=$_POST["title"];
$this->f->save($title, $url);
header('location:http://localhost/CodeIgniter2/index.php');
}
private function do_upload()
{
$type=explode('.',$_FILES["poza"]["name"]);
$type=$type[count($type)-1];
$url="./images/".$_FILES["poza"]["name"];
if(in_array($type,array("jpg","jpeg","gif","png")))
if(is_uploaded_file($_FILES["poza"]["tmp_name"]))
if(move_uploaded_file($_FILES["poza"]["tmp_name"],
$url))
return $url;
return "";
}
public function delete($id){
$id=$this->db->where('id',$id);
$this->db->delete('images');
header('location:http://localhost/CodeIgniter2/inde
x.php');
//redirect('MainController/index');
}
public function edit($id){
$row=$this->f->getImage($id);
$data['r']=$row;
$this->load->view('edit_view',$data);
}
public function update(){
$id=$this->input->post('id');
//create array with input data
$data=array(
'title'=>$this->input->post('title'),
'image'=>"./images/".$_FILES["poza"]["name"]
);
$title=$this->input->post('title');
$image="./images/".$_FILES["poza"]["name"];
move_uploaded_file($_FILES["poza"]["tmp_name"], $image);
//update data
// $this->f->update($title,$image,$id);
$this->db->where('id',$id);
$this->db->update('images',$data);
//redirect
header('location:http://localhost/CodeIgniter2/index.php');
}
}
MainModel.php
<?php
class MainModel extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function save($title,$url)
{
$this->db->set('title',$title);
$this->db->set('image',$url);
$this->db->insert('images');
}
public function update($title,$image,$id){
$this->db->set('title',$title);
$this->db->set('image',$image);
$this->db->where('id',$id);
}
public function getImages(){
$this->db->select('id,title,image')->from('images');
$query = $this->db->get();
return $query->result();
}
function getImage($id){
$this->db->where('id',$id);
$query = $this->db->get('images');
return $query->row();
}
}
edit_view.php
<?php
//$this->load->helper('form');
echo form_open_multipart('MainController/update/');
$data1 = ['name' => 'title',
'id' => 'title',
'value'=>$r->title,
'maxlength' => '100',
'size' => '30',
];
$data2 = ['name' => 'poza',
'id' => 'poza',
'value'=>$r->image,
'maxlength' => '100',
'size' => '30',
];
$data3 = ['name' => 'id',
'id' => 'id',
'type'=>'hidden',
'value'=>$r->id,
'maxlength' => '100',
'size' => '30',
];
?>
<?php echo form_input($data3);?>
<table>
<tr>
<td><?php echo form_label('Title ', 'title');?></td>
<td><?php echo form_input($data1);?></td>
</tr>
<tr>
<td><?php echo form_label('Image ', 'poza');?></td>
<td><?php echo form_upload($data2);?></td>
</tr>
</table>
<?php echo form_submit('submit', 'Update');?>
upload.php
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<?php echo form_open_multipart('MainController/save'); ?>
<table class="table">
<tr>
<td>Titlu</td>
<td><?php echo form_input('title');?></td>
</tr>
<tr>
<td>Imagine</td>
<td><?php echo form_upload('poza');?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit','Save','class="btn btn-primary"')?></td>
</tr>
</table>
</body>
</html>
view.php
<!DOCTYPE html>
<head>
</head>
<body>
<table>
<tr>
<td><strong>Nume</strong></td>
<td><strong>Imagine</strong></td>
<td colspan="3"><strong>Actions</strong></td>
</tr>
<?php foreach($this->f->getImages() as $var){?>
<tr>
<td><?php echo $var->title;?></td>
<td><img src="<?php echo base_url($var->image);?>"
width="100" height="100"></td>
<td><?php echo anchor(array('MainController/view/',$var-
>id),'View');?> </td>
<td><?php echo anchor(array('MainController/edit/',$var-
>id),'Edit');?> </td>
<td><?php echo anchor(array('MainController/delete/',$var-
>id), 'Delete',array('onclick' => "return confirm('Do you want delete
this record')"));?> </td>
</tr>
<?php }?>
</table
<br><br>
<?php echo anchor(array('MainController/upload/'),'Upload another
image'); ?>
</body>
</html>
view_single.php
<h2><?php echo $r->title; ?></h2>
<h2><img src="<?php echo base_url($r->image);?>"
width="100" height="100"></h2>
<a href="<?php echo site_url() ?>">Back</a>

Contenu connexe

Tendances

Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
desaipratu10
 
Contact Management System
Contact Management SystemContact Management System
Contact Management System
Gopal Bhat
 
Airline Reservation Software Requirement Specification
Airline Reservation Software Requirement SpecificationAirline Reservation Software Requirement Specification
Airline Reservation Software Requirement Specification
Deborah Kronk
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
inteldualcore
 

Tendances (20)

Introduction to DBMS and SQL Overview
Introduction to DBMS and SQL OverviewIntroduction to DBMS and SQL Overview
Introduction to DBMS and SQL Overview
 
Data Flow Diagram
Data Flow DiagramData Flow Diagram
Data Flow Diagram
 
Oracle Apps - Forms
Oracle Apps - FormsOracle Apps - Forms
Oracle Apps - Forms
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
 
Process model in SE
Process model in SEProcess model in SE
Process model in SE
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
 
Iterative and Incremental Development (RAD)
Iterative  and Incremental Development (RAD)Iterative  and Incremental Development (RAD)
Iterative and Incremental Development (RAD)
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and Design
 
Data flow diagram
Data flow diagramData flow diagram
Data flow diagram
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
 
Contact Management System
Contact Management SystemContact Management System
Contact Management System
 
Activity diagram-UML diagram
Activity diagram-UML diagramActivity diagram-UML diagram
Activity diagram-UML diagram
 
Airline Reservation Software Requirement Specification
Airline Reservation Software Requirement SpecificationAirline Reservation Software Requirement Specification
Airline Reservation Software Requirement Specification
 
Directives in asp.net
Directives in asp.netDirectives in asp.net
Directives in asp.net
 
Java web services
Java web servicesJava web services
Java web services
 
Object oriented modeling and design
Object oriented modeling and designObject oriented modeling and design
Object oriented modeling and design
 
Passport Automation System
Passport Automation SystemPassport Automation System
Passport Automation System
 
Behavioural modelling
Behavioural modellingBehavioural modelling
Behavioural modelling
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
 

Similaire à 20. CodeIgniter edit images

Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 

Similaire à 20. CodeIgniter edit images (20)

15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor15. CodeIgniter editarea inregistrarilor
15. CodeIgniter editarea inregistrarilor
 
21. CodeIgniter search
21. CodeIgniter search21. CodeIgniter search
21. CodeIgniter search
 
19. CodeIgniter imagini in mysql
19. CodeIgniter imagini in mysql19. CodeIgniter imagini in mysql
19. CodeIgniter imagini in mysql
 
16. CodeIgniter stergerea inregistrarilor
16. CodeIgniter stergerea inregistrarilor16. CodeIgniter stergerea inregistrarilor
16. CodeIgniter stergerea inregistrarilor
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
23. CodeIgniter sessions
23. CodeIgniter sessions23. CodeIgniter sessions
23. CodeIgniter sessions
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request Flow
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On Rails
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 

Plus de Razvan Raducanu, PhD

Plus de Razvan Raducanu, PhD (20)

12. edit record
12. edit record12. edit record
12. edit record
 
11. delete record
11. delete record11. delete record
11. delete record
 
10. view one record
10. view one record10. view one record
10. view one record
 
9. add new record
9. add new record9. add new record
9. add new record
 
7. copy1
7. copy17. copy1
7. copy1
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
4. forme in zend framework 3
4. forme in zend framework 34. forme in zend framework 3
4. forme in zend framework 3
 
3. trimiterea datelor la vederi
3. trimiterea datelor la vederi3. trimiterea datelor la vederi
3. trimiterea datelor la vederi
 
2.routing in zend framework 3
2.routing in zend framework 32.routing in zend framework 3
2.routing in zend framework 3
 
1. zend framework intro
1. zend framework intro1. zend framework intro
1. zend framework intro
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
17. delete data
17. delete data17. delete data
17. delete data
 
16. edit data
16. edit data16. edit data
16. edit data
 
15. view single data
15. view single data15. view single data
15. view single data
 
14. add data in symfony4
14. add data in symfony4 14. add data in symfony4
14. add data in symfony4
 
13. view data
13. view data13. view data
13. view data
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
 
11. move in Symfony 4
11. move in Symfony 411. move in Symfony 4
11. move in Symfony 4
 
10. add in Symfony 4
10. add in Symfony 410. add in Symfony 4
10. add in Symfony 4
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Dernier (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

20. CodeIgniter edit images