Commit 92467d34 by tetiana yaremko

upload file on live server

parent b62a53e2
...@@ -9,3 +9,6 @@ handlers: ...@@ -9,3 +9,6 @@ handlers:
- url: /.* - url: /.*
script: index.php script: index.php
env_variables:
GOOGLE_STORAGE_BUCKET: "wbt-2-ty-272811.appspot.com"
...@@ -536,3 +536,15 @@ $config['rewrite_short_tags'] = FALSE; ...@@ -536,3 +536,15 @@ $config['rewrite_short_tags'] = FALSE;
| Array: array('10.0.1.200', '192.168.5.0/24') | Array: array('10.0.1.200', '192.168.5.0/24')
*/ */
$config['proxy_ips'] = ''; $config['proxy_ips'] = '';
$config['upload_bucket'] = 'wbt-2-ty-272811.appspot.com';
$config['upload_path'] = ENVIRONMENT == 'production' ?
'gs://' . $config['upload_bucket']
: './uploads/';
// Prefix for building public URL to the uploaded file
$config['upload_prefix'] = ENVIRONMENT == 'production' ?
'https://storage.cloud.google.com/' .
$config['upload_bucket'] . '/'
: $config['base_url'] . 'uploads/';
...@@ -24,13 +24,16 @@ class Admin extends CI_Controller { ...@@ -24,13 +24,16 @@ class Admin extends CI_Controller {
$this->form_validation->set_rules("price", "Price", "required"); $this->form_validation->set_rules("price", "Price", "required");
$this->form_validation->set_rules("description", "Description", "required"); $this->form_validation->set_rules("description", "Description", "required");
$config['upload_path'] = './uploads/';
//$config['upload_path'] = './uploads/';
$config['upload_path'] = $this->config->item('upload_path');
$config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 4048; $config['max_size'] = 4048;
$file_name="image".time(); $file_name="image".time();
$config['file_name']=$file_name; $config['file_name']=$file_name;
$config['encrypt_name'] = TRUE;
$this->upload->initialize($config); $this->upload->initialize($config);
$field_name = "image"; $field_name = "file";
if ($this->form_validation->run() == TRUE) { if ($this->form_validation->run() == TRUE) {
if(!$this->upload->do_upload($field_name)) { if(!$this->upload->do_upload($field_name)) {
...@@ -41,6 +44,7 @@ class Admin extends CI_Controller { ...@@ -41,6 +44,7 @@ class Admin extends CI_Controller {
} else { } else {
$this->load->model('Admin_model', 'admin'); $this->load->model('Admin_model', 'admin');
$this->admin->add_product(); $this->admin->add_product();
$this->session->set_flashdata("message", "<div class=\"alert alert-success alert-dismissible fade show\" role=\"alert\"> $this->session->set_flashdata("message", "<div class=\"alert alert-success alert-dismissible fade show\" role=\"alert\">
Product has been added to the database<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"> Product has been added to the database<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">
...@@ -77,13 +81,21 @@ class Admin extends CI_Controller { ...@@ -77,13 +81,21 @@ class Admin extends CI_Controller {
$this->form_validation->set_rules("description", "Description", "required"); $this->form_validation->set_rules("description", "Description", "required");
$this->form_validation->set_rules("status", "Status", "required"); $this->form_validation->set_rules("status", "Status", "required");
$config['upload_path'] = './uploads/'; // $config['upload_path'] = './uploads/';
// $config['allowed_types'] = 'gif|jpg|png|jpeg';
// $config['max_size'] = 2048;
// $file_name="image".time();
// $config['file_name']=$file_name;
// $this->upload->initialize($config);
// $field_name = "file";
$config['upload_path'] = $this->config->item('upload_path');
$config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 2048; $config['max_size'] = 4048;
$file_name="image".time(); $file_name="image".time();
$config['file_name']=$file_name; $config['file_name']=$file_name;
$config['encrypt_name'] = TRUE;
$this->upload->initialize($config); $this->upload->initialize($config);
$field_name = "image"; $field_name = "file";
if ($this->form_validation->run() == TRUE) { if ($this->form_validation->run() == TRUE) {
if(!$this->upload->do_upload($field_name)) { if(!$this->upload->do_upload($field_name)) {
......
...@@ -25,7 +25,8 @@ class Admin_model extends CI_Model ...@@ -25,7 +25,8 @@ class Admin_model extends CI_Model
$query = $this->db->get(); $query = $this->db->get();
$status_id=$query->row(); $status_id=$query->row();
$image =$this->upload->data(); //$image =$this->upload->data();
$image= $this->config->item('upload_prefix'). $this->upload->data('file_name');
//insert data from add_product input //insert data from add_product input
$data = array( $data = array(
...@@ -35,7 +36,7 @@ class Admin_model extends CI_Model ...@@ -35,7 +36,7 @@ class Admin_model extends CI_Model
'q_ty' => $this->input->post('quantity'), 'q_ty' => $this->input->post('quantity'),
'price' => $this->input->post('price'), 'price' => $this->input->post('price'),
'description' => $this->input->post('description'), 'description' => $this->input->post('description'),
'image' =>$image['file_name'], 'image' =>$image,
'feature' =>$this->input>post('feature'), 'feature' =>$this->input>post('feature'),
'status_id'=>(int)$status_id->id_status 'status_id'=>(int)$status_id->id_status
); );
......
...@@ -117,11 +117,11 @@ ...@@ -117,11 +117,11 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<?php $error =form_error("image", "<small class='text-danger'>", '</small>');?> <?php $error =form_error("file", "<small class='text-danger'>", '</small>');?>
<label for="image">Image</label> <label for="image">Image</label>
</td> </td>
<td> <td>
<input name="image" type="file" class="form-control-file" id="image" aria-describedby="fileHelp"> <input name="file" type="file" class="form-control-file" id="image" aria-describedby="fileHelp">
<div> <?php echo $error; ?></div> <div> <?php echo $error; ?></div>
</td> </td>
</tr> </tr>
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
<label for="image">Image</label> <label for="image">Image</label>
</td> </td>
<td> <td>
<input name="image" type="file" class="form-control-file" id="image" aria-describedby="fileHelp" value="<?php set_value(base_url("uploads/".$data->image) )?>"> <input name="file" type="file" class="form-control-file" id="image" aria-describedby="fileHelp" value="<?php set_value(base_url("uploads/".$data->image) )?>">
</td> </td>
</tr> </tr>
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<body> <body>
<div class="head-offer"> <div class="head-offer">
<div class="offer-list"> <div class="offer-list">
<ul class="navigation offer"> <ul class="navigation offer">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment